When uploading a file, you often need to determine whether the folder exists. If yes, upload the file. Otherwise, create a folder and upload the file.
This is probably the syntax.
String dir = "d: xxxyyy"
If (system. io. directory. exists (dir ))
{
// Exists
}
Else
{
// Does not exist
}
Next let's take a look at the detailed code
The judgment statement is
If (system. io. directory. exists (server. mappath ("file") = false) // create a file folder if it does not exist
{
System. io. directory. createdirectory (server. mappath ("file "));
}
System. io. directory. delete (server. mappath ("file"), true); // delete folders, subdirectories, files
Determine the existence of a file
If (system. io. file. exist (server. mappath ("~ /Back/data. xml "))
{
// File exists
}
Else
{
// The file does not exist.
Directory. create (server. mappath ("~ /Back/data. xml "); // create the file
Reference
System. io. file. exists (file path)
System. io. directory. exists (Folder path)
System. io. directory. getdirectories (Folder path) Get subdirectory
System. io. directory. exists (folderpath );
System. io. file. exists (filename );
Directoryinfo folder = new directoryinfo (path );
Fileinfo [] subfiles = folder. getfiles ();