Copy all files in the specified folder to the target folder.

Source: Internet
Author: User

 

Code
///   <Summary>
/// Copy all content under the specified folder to the target folder
///   </Summary>
///   <Param name = "srcpath"> Original path </Param>
///   <Param name = "aimpath"> Target folder </Param>
Public   Void Copydir ( String Srcpath, String Aimpath)
{
Try
{
// Check whether the target directory ends with a directory delimiter. If not, add it.
If (Aimpath [aimpath. Length -   1 ] ! = Path. directoryseparatorchar)
{
Aimpath + = Path. directoryseparatorchar;
}
// Determine whether the target directory exists. If it does not exist, create it.
If (Directory. exists (aimpath ))
{
This . Deletefolder (aimpath. substring ( 0 , Aimpath. Length -   1 ));
}
Directory. createdirectory (aimpath );
// If you direct to the file under the copy target file without including the directory, use the following method:
String [] Filelist = Directory. getfilesystementries (srcpath );
// Traverse all files and directories
Foreach ( String File In Filelist)
{
// First, process the file as a directory. If this directory exists, recursively copy the file under this directory.
If (Directory. exists (File ))
Copydir (file, aimpath + Path. getfilename (File ));
// Otherwise, copy the file directly.
Else
File. Copy (file, aimpath + Path. getfilename (file ), True );
}
}
Catch (Exception ee)
{
Throw   New Exception (EE. tostring ());
}
}

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.