/*************************************** **************************************** ********************
** Function name: copyfolder
** Input: const cstring & DESC Destination path
** Const cstring & source Source Path
** Output:
** Function Description: recursive copy of folders
** Global variables:
** Call module:
** Author: Liu Zhiyong
** Date:
** Modification:
** Date:
** Version:
**************************************** **************************************** *******************/
Bool cfolderoperater: copyfolder (const cstring & DESC, const cstring & source)
{
Try
{
Cstring tmpfrom (source );
Cstring tmpto (DESC );
If (! Pathfileexists (tmpto ))
{
Createdirectory (tmpto, null );
}
If (pathfileexists (tmpfrom ))
{
Win32_find_data findfiledata;
Cstring tmpfind (tmpfrom );
Tmpfind + = _ T ("//*.*");
Handle hfind =: findfirstfile (tmpfind, & findfiledata );
If (invalid_handle_value = hfind)
Return false;
While (true)
{
Cstring tmpfile (tmpto );
Tmpfile + = _ T ("//");
Tmpfile + = findfiledata. cfilename;
If (findfiledata. dwfileattributes & file_attribute_directory) // directory
{
If (findfiledata. cfilename [0]! = '.')
{
If (! Pathfileexists (tmpfile) // The directory does not exist
{
Createdirectory (tmpfile, null );
}
Copyfolder (tmpfile, tmpfrom + _ T ("//") + findfiledata. cfilename );
}
}
Else // File
{
Cstring sextention = pathfindextension (tmpfile );
If (! Pathfileexists (tmpfile) // the file does not exist
{
Copyfile (tmpfrom + _ T ("//") + findfiledata. cfilename, tmpfile, true); // copy the object
}
Else if (sextention! = _ T (". mdb "))
{
Copyfile (tmpfrom + _ T ("//") + findfiledata. cfilename, tmpfile, true); // copy the object
}
Else if (sextention = _ T (". mdb") // if the data extension is Access database, change the name of the target database and then copy it.
{
// Int dwminsize = widechartomultibyte (cp_oemcp, null, tmpfile,-1, null, 0, null, false );
// Char lpszstr [max_path + 1];
// Widechartomultibyte (cp_oemcp, null, tmpfile,-1, lpszstr, dwminsize, null, false );
Wchar wflag = '//';
Int NPOs = tmpfile. reversefind (wflag );
Int nlen = tmpfile. getlength ();
Cstring sfront = tmpfile. mid (0, NPOs );
Cstring sback = _ T ("old. mdb ");
Cstring snewname = sfront + _ T ("//") + sback;
// Int dwnewminsize = widechartomultibyte (cp_oemcp, null, snewname,-1, null, 0, null, false );
// Char lpsznewstr [max_path + 1];
// Widechartomultibyte (cp_oemcp, null, snewname,-1, lpsznewstr, dwnewminsize, null, false );
Rename (tmpfile, snewname );
Copyfile (tmpfrom + _ T ("//") + findfiledata. cfilename, tmpfile, true); // copy the object
Cdbrestore dbrestore;
Dbrestore. restoredata (tmpfile, snewname );
Deletefile (snewname );
}
}
If (! Findnextfile (hfind, & findfiledata ))
Break;
}
Findclose (hfind );
}
Return true;
}
Catch (...)
{
Return false;
}
}