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;