Copy all the contents of a folder into another folder:
1 public static void Copydir (String srcpath, String Aimpath) 2 {3 Try 4 {5
Checks whether the target directory ends with a directory split character if not, add 6 if (Aimpath[aimpath.length-1]!= Path.directoryseparatorchar)
7 Aimpath + + Path.directoryseparatorchar; 8//Determine if the target directory exists if it does not exist, the new 9 if (!
Directory.Exists (Aimpath)) directory.createdirectory (Aimpath); 11//Get the source directory of the file list, which is included file and directory path of an array 12//If you point to the copy target file below the file without the directory please use the following method 13
string[] filelist = Directory.GetFiles (Srcpath);
string[] filelist = directory.getfilesystementries (Srcpath); 15//Traverse all files and directories by foreach (string file in FileList) 17 {18 Treat as directory first if there is this directory, recursively copy the file under this directory, directory.exists (file) Co Pydir (file, Aimpath + path.getfilename (file)); 21//or else direct Copy file file.copy (file, Aimpath + Path .
GetFileName (file), true); Console.WriteLine ("Unable to copy!")
; 29} 30}
To delete a folder:
Directory.delete (path, true);
This article by Whchina (Jiangcheng old temperature) original release, reprint please indicate the source, Jiangcheng old Wen as a thinker.