Copy folder for folder action classes in C # encapsulation

Source: Internet
Author: User

Copy folder for folder action classes in C # encapsulation

I. Copy folder principle:

1. Recursively traverse a folder

2. Copying files

Two. FolderHelper.cs

1  /// <summary>2     ///Folder Action Class3     /// </summary>4      Public Static classFolderhelper5     {6         /// <summary>7         ///Copy Folder8         /// </summary>9         /// <param name= "Sourcefoldername" >source folder Directory</param>Ten         /// <param name= "Destfoldername" >Destination Folder Directory</param> One          Public Static voidCopy (stringSourcefoldername,stringdestfoldername) A         { -Copy (Sourcefoldername, Destfoldername,false); -         } the  -         /// <summary> -         ///Copy Folder -         /// </summary> +         /// <param name= "Sourcefoldername" >source folder Directory</param> -         /// <param name= "Destfoldername" >Destination Folder Directory</param> +         /// <param name= "Overwrite" >allow overwriting of files</param> A          Public Static voidCopy (stringSourcefoldername,stringDestfoldername,BOOLoverwrite) at         { -             varSourcefilespath =directory.getfilesystementries (sourcefoldername); -  -              for(inti =0; i < sourcefilespath.length; i++) -             { -                 varSourcefilepath =Sourcefilespath[i]; in                 varDirectoryName =Path.getdirectoryname (sourcefilepath); -                 varForlders = Directoryname.split ('\\'); to                 varLastdirectory = Forlders[forlders. Length-1]; +                 varDest =Path.Combine (Destfoldername, lastdirectory); -  the                 if(File.exists (sourcefilepath)) *                 { $                     varsourceFileName =Path.getfilename (sourcefilepath);Panax Notoginseng                     if(!directory.exists (dest)) -                     { the directory.createdirectory (dest); +                     } A file.copy (Sourcefilepath, Path.Combine (dest, sourceFileName), overwrite); the                 } +                 Else -                 { $ Copy (Sourcefilepath, dest, overwrite); $                 } -             } -         } the}

Copy folder for folder action classes in C # encapsulation

Related Article

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.