C # J Basic Operations-copy all contents of a folder to another folder: Copy code 1 public static void Copydir (string Srcpath, string to implement folder replication and deletion

Source: Internet
Author: User

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.

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.