C # Check whether folders and files exist

Source: Internet
Author: User

 

// 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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.