C # implements methods for copying files from folders to another folder

Source: Internet
Author: User

private void Copydir (String srcpath, String aimpath)
{
Try
{
//checks whether the destination directory ends with a directory split character, if not, adds
if (aimpat H[AIMPATH.LENGTH-1]! = System.IO.Path.DirectorySeparatorChar)
{
Aimpath + = System.IO.Path.DirectorySeparatorChar;
}
//Determine if the destination directory exists if it does not exist, then create a new
if (! System.IO.Directory.Exists (Aimpath))
{
System.IO.Directory.CreateDirectory (aimpath);
}
//Get a list of files from the source directory, which is an array containing the files and directory paths
//If you point to a file below the copy destination file without a directory, use the following method
//string[] FileList = Directory.GetFiles (Srcpath);
string[] fileList = System.IO.Directory.GetFileSystemEntries (Srcpath);
// Traverse all files and directories
foreach (string file in FileList)
{
//first as directory processing if the directory is present, recursively copy the file under the directory
if (System.IO.Directory . Exists (file))
{
Copydir (file, Aimpath + System.IO.Path.GetFileName (file));
}
//Otherwise direct Copy file
Else
{
System.IO.File.Copy (file, Aimpath + System.IO.Path.GetFileName (file), true);
}
}
}
catch (Exception e)
{
throw;
}
}

C # implements methods for copying files from folders to another folder

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.