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
- BOOL Cutility::copyfolder (lpctstr lpszfrompath,lpctstr lpsztopath)
- {
- size_t nlengthfrm = _tcslen (Lpszfrompath);
- TCHAR *newpathfrm = new tchar[nlengthfrm+2];
- _tcscpy (Newpathfrm,lpszfrompath);
- NEWPATHFRM[NLENGTHFRM] = ' + ';
- NEWPATHFRM[NLENGTHFRM+1] = ' + ';
- Shfileopstruct Fileop;
- ZeroMemory (void*) &fileop,sizeof (SHFILEOPSTRUCT));
- Fileop.fflags = fof_noconfirmation| fof_noconfirmmkdir| fof_noerrorui| fof_filesonly| Fof_nocopysecurityattribs;
- Fileop.hnamemappings = NULL;
- Fileop.hwnd = NULL;
- Fileop.lpszprogresstitle = NULL;
- Fileop.pfrom = newpathfrm;
- Fileop.pto = Lpsztopath;
- Fileop.wfunc = fo_copy;
- return return SHFileOperation (&FILEOP);
- }
Code compare Russell. Time to complete replication: 57,923 milliseconds.
Scenario 2: Calling Api:copyfile
[CPP]View PlainCopy
- BOOL Cutility::copyfolder (lpctstr lpszfrompath,lpctstr lpsztopath)
- {
- return CopyFile (Lpszfrompath, Lpsztopath, TRUE);
- }
Code is short and concise. Replication time: 700 milliseconds.
Scenario 3: Call the cmd command.
[CPP]View PlainCopy
- BOOL Cutility::copyfolder (lpctstr lpszfrompath,lpctstr lpsztopath)
- {
- TCHAR tbuff[255];
- Char buff[255];
- _stprintf (Tbuff, _t ("copy/y%s%s"), Lpszfrompath, Lpsztopath);
- Tchar2char (Tbuff, buff, 255);
- System (buff);
- return TRUE;
- }
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