The choice of copying files in a Windows program

Source: Internet
Author: User

Recently, you need to copy a large number of small files under Windows (more than 100,000 levels). Write some copy files of small program, unexpectedly found different choice, copy speed has a difference!

The existing test data: 1500+ small files, the total size of about 10M. Copies are now made in different ways. :

Scenario 1: Calling SHFileOperation

[CPP]View PlainCopy
  1. BOOL Cutility::copyfolder (lpctstr lpszfrompath,lpctstr lpsztopath)
  2. {
  3. size_t nlengthfrm = _tcslen (Lpszfrompath);
  4. TCHAR *newpathfrm = new tchar[nlengthfrm+2];
  5. _tcscpy (Newpathfrm,lpszfrompath);
  6. NEWPATHFRM[NLENGTHFRM] = ' + ';
  7. NEWPATHFRM[NLENGTHFRM+1] = ' + ';
  8. Shfileopstruct Fileop;
  9. ZeroMemory (void*) &fileop,sizeof (SHFILEOPSTRUCT));
  10. Fileop.fflags = fof_noconfirmation| fof_noconfirmmkdir| fof_noerrorui| fof_filesonly| Fof_nocopysecurityattribs;
  11. Fileop.hnamemappings = NULL;
  12. Fileop.hwnd = NULL;
  13. Fileop.lpszprogresstitle = NULL;
  14. Fileop.pfrom = newpathfrm;
  15. Fileop.pto = Lpsztopath;
  16. Fileop.wfunc = fo_copy;
  17. return return SHFileOperation (&FILEOP);
  18. }


Code compare Russell. Time to complete replication: 57,923 milliseconds.

Scenario 2: Calling Api:copyfile

[CPP]View PlainCopy
    1. BOOL Cutility::copyfolder (lpctstr lpszfrompath,lpctstr lpsztopath)
    2. {
    3. return CopyFile (Lpszfrompath, Lpsztopath, TRUE);
    4. }

Code is short and concise. Replication time: 700 milliseconds.

Scenario 3: Call the cmd command.

[CPP]View PlainCopy
    1. BOOL Cutility::copyfolder (lpctstr lpszfrompath,lpctstr lpsztopath)
    2. {
    3. TCHAR tbuff[255];
    4. Char buff[255];
    5. _stprintf (Tbuff, _t ("copy/y%s%s"), Lpszfrompath, Lpsztopath);
    6. Tchar2char (Tbuff, buff, 255);
    7. System (buff);
    8. return TRUE;
    9. }

Ran to 5 minutes after the direct card to die. There is no result, possibly a problem with parameter passing.

http://blog.csdn.net/lsldd/article/details/8191338

The choice of copying files in a Windows program

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.