// ================================================ ========================================
// 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;
}