Source code of recursive folder copy

Source: Internet
Author: User

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

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.