Allows the path parameter to specify relative or absolute path information. Relative path information is interpreted as compared to the current working directory.
Remove trailing spaces from the end of the path parameter before checking for the existence of the directory.
The path parameter is case-insensitive.
If you do not have the minimum read-only permission for the directory, the Exists method returns 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
I'm looking at a detailed example.
To determine the existence of a folder, create, delete folder
String aaaa = "F:notebookhaha";//the correct way of writing the path
if (directory.exists (AAAA))//Create a file folder if it does not exist
{
MessageBox.Show ("Existing folder");
Directory.delete (AAAA, false);//If there is a file or directory in the folder, an error is shown here
Directory.delete (AAAA, true);//true represents the deletion of folders and subdirectories and files inside them
}
Else
{
MessageBox.Show ("No folder Exists");
Directory.CreateDirectory (AAAA);//Create the folder
}
To determine the existence, creation, and deletion of files
String dddd = aaaa + "11.txt";
if (file.exists (dddd))
{
MessageBox.Show ("existing document");
File.delete (dddd);//Delete the file
}
Else
{
MessageBox.Show ("No document Exists");
File.create (dddd);//Create the file, if the path folder does not exist, the error.
}
<span style= "Font-family:verdana, ' Courier New '" face= "Verdana, ' Courier New '" ><span style= "font-size:15px; line-height:18px; White-space:normal ">
</span></span>
About friends said File.exists () on the network map of the file, whether existing or not, all return false below to see the detailed description
There is no problem with file.exists () itself. You can try and do the same thing in WinForm without any errors.
The reason for this is to return false to shared files on other machines on ASP tutorials, whether they exist or not, primarily as a matter of user rights. When running
The ASP.net tutorial program is not run with the current user rights, but with the ASPNET user right. For security reasons, this right is vs.net
The version has more stringent restrictions. Returns False when the permissions of the ASPNET do not have permission to view the shared file.
There is a workaround: You can change the user rights for the ASP.net program, and in the Web.config file, specify a
Specific users:
<identity impersonate= "true" Username= "AccountName" password= "password"/>
After testing, you should be able to directly detect the existence of shared files for other machines:
BOOL A = file.exists ("Othercomputersharetest.txt");
(There will still be a problem detecting the files on the network map disk).