EVC allows you to copy all files in a folder.

Source: Internet
Author: User

// ================================================ ========================================
// Title:
// EVC copies all files in the folder
// Author:
// Norains
// Date:
// Wednesday 17-may-2006.
// ================================================ ========================================

In EVC, all files (including folders) in a folder are copied to another folder. The algorithm is not complex and simple.
// Szexistingdir: source folder
// Sznewdir: Target folder
// Note: The target folder must exist; otherwise, the function returns false.
Bool browseandcopy (const cstring szexistingdir, const cstring sznewdir)
{
Cstring szexistdir; // Save the source folder path
Cstring szaimdir = sznewdir; // Save the path of the target folder.

Cstring szfinddir = szexistingdir;
If (szfinddir. Right (1 )! = "//")
{
Szfinddir + = "//";
Szexistdir = szfinddir;
}
Szfinddir + = "*. *"; // search all files

Win32_find_data FD;
Handle hfind;
Hfind = findfirstfile (szfinddir, & FD); // find the first file
If (hfind! = Invalid_handle_value)
{
Do {
If (FD. dwfileattributes = file_attribute_directory) // you can check whether a folder exists.
{
If (szaimdir. Right (1 )! = "//")
{
Szaimdir + = "//";
}
Createdirectory (szaimdir + FD. cfilename, null); // create a subfolder in the target folder
Browseandcopy (szexistdir + FD. cfilename, szaimdir + FD. cfilename); // recursively searches for files in subfiles
}
Else
{
If (szaimdir. Right (1 )! = "//")
{
Szaimdir + = "//";
}

If (copyfile (szexistdir + FD. cfilename, szaimdir + FD. cfilename, false) = false) // copy the file to the target folder
{
Return false;
}

}

} While (findnextfile (hfind, & FD); // you can check whether the next file exists.
}
Else
{
// If the source folder is empty, return
Return false;
}

Return true;

}

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.