允许 path 参数指定相对或绝对路径信息。 相对路径信息被解释为相对于当前工作目录。
检查该目录是否存在之前,从 path 参数的末尾移除尾随空格。
path 参数不区分大小写。
如果您没有该目录的最小只读权限,exists 方法将返回 false。
if directory.exists(path) then ' this path is a directory. processdirectory(path) else console.writeline("{0} is not a valid file or directory.", path) end if
下在看一款详细的实例
//判断文件夹的存在、创建、删除文件夹 string aaaa = "f:notebookhaha";//路径的正确写法 if (directory.exists(aaaa))//如果不存在就创建file文件夹 { messagebox.show("存在文件夹"); //directory.delete(aaaa, false);//如果文件夹中有文件或目录,此处会报错 //directory.delete(aaaa, true);//true代表删除文件夹及其里面的子目录和文件 } else messagebox.show("不存在文件夹"); directory.createdirectory(aaaa);//创建该文件夹 //判断文件的存在、创建、删除文件 string dddd = aaaa + "11.txt"; if (file.exists(dddd)) messagebox.show("存在文件"); file.delete(dddd);//删除该文件 messagebox.show("不存在文件"); file.create(dddd);//创建该文件,如果路径文件夹不存在,则报错。 <span style="font-family: verdana, 'courier new'" face="verdana, 'courier new'"><span style="font-size: 15px; line-height: 18px; white-space: normal"> </span></span>
关于朋友说file.exists() 对网络映射盘上的文件,不论存在与否,一律返回false下面来看看详细说明
file.exists()本身没有问题。您可以试一下,在winform中完成同样的功能不会出任何错误。
式版有比较严格的限制。当aspnet权限无权查看该共享文件,则返回false。
有一个workaround:您可以更改该asp.net程序的用户权限,在web.config文件中为该asp.net应用程序指定一个
特定的用户:
<identity impersonate="true" username="accountname" password="password" />
经过测试,这时应该能够直接检测到其他机器的共享文件是否存在:
(检测网络映射盘上的文件仍会有问题)。