File, folder basic operations

Source: Internet
Author: User

1: Create a folder using the Create () method of the DirectoryInfo class;

For example, string name = txtName. text;

String path = @ "D: \ Programe Files" + name;

DirectoryInfo directoryInfo = new DirectoryInfo (path );

If (directoryInfo. Exist)

{
MessageBox. Show ("the current folder already exists in the directory ");
Return;
}
Else

{
DirectoryInfo. Create ();

MessageBox. Show ("folder created successfully ");

}

NOTE: If DirectoryInfo directoryInfo = new DirectoryInfo (path );

Change to DirectoryInfo directoryInfo = new DirectoryInfo (name). The directory is created in the Debug directory of the project.

You can also use the directoryInfo. Delete () method to Delete folders, The directoryInfo. MoveTo () method to move folders, And the directoryInfo. GetAllFiles () method to traverse all files in the folder.

2: Create a File to apply the Create () Static Method of the File class;

For example, string name = txtName. text;

String path = @ "D: \ Programe Files" + name;

File. Create (path); a File named name is created in the specified location;

Note: You can call File. Delete (path) to Delete a File and File. Copy (path, newPath) to Copy the File;

3: to obtain the basic information of a file, use the FileInfo class to map the file;

For example, FileInfo fileInfo = new FileInfo (path); you can use fileInfo to obtain the basic information of a file;

 

 

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.