// Determine the existence, creation, and deletion of a folder string AAAA = "F: \ notebook \ Haha \"; // the correct way to write the path if (directory. exists (aaaa) // create a file folder {MessageBox. show ("folder"); // directory. delete (aaaa, false); // if a file or directory exists in the folder, an error is returned. // directory. delete (aaaa, true); // true indicates deleting folders and Their subdirectories and files.} else {MessageBox. show ("Folder does not exist"); directory. createdirectory (aaaa); // create this folder} // determine the existence, creation, and deletion of the file string dddd = AAAA + "11.txt"; If (file. exists (dddd )){ MessageBox. show ("existing file"); file. delete (dddd); // Delete this file} else {MessageBox. show ("file does not exist"); file. create (dddd); // create the file. If the path Folder does not exist, an error is returned. }
Note:
When creating a database in the previous article, you can first check whether the file exists.
If a database file exists, skip the "create database" section.
If no database file exists, check whether the path exists.
Create a folder if it does not exist.