-
-
Save myd7349/7598dbb435d6198887c89b6bf8951e5d to your computer and use it in GitHub Desktop.
SHFileOperation for recursive folder copy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| bool SHCopy(LPCTSTR from, LPCTSTR to) | |
| { | |
| Log(_T("Recursive file copy from %s to %s"), from, to); | |
| SHFILEOPSTRUCT fileOp = {0}; | |
| fileOp.wFunc = FO_COPY; | |
| TCHAR newFrom[MAX_PATH]; | |
| _tcscpy_s(newFrom, from); | |
| newFrom[_tcsclen(from) + 1] = NULL; | |
| fileOp.pFrom = newFrom; | |
| TCHAR newTo[MAX_PATH]; | |
| _tcscpy_s(newTo, to); | |
| newTo[_tcsclen(to) + 1] = NULL; | |
| fileOp.pTo = newTo; | |
| fileOp.fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_NOCONFIRMMKDIR; | |
| int result = SHFileOperation(&fileOp); | |
| Log(_T("SHFileOperation return code: 0x%x"), result); | |
| return result == 0; | |
| } | |
| //sample call, E:\ is a USB stick | |
| bool result = SHCopy(_T("E:\\*"), _T("C:\\SomeDirectory\\")); | |
| //when called on XP SP3 and with the flag FOF_SILENT, this fails with 0x4C7 (ERROR_CANCELLED) | |
| //removal of FOF_SILENT makes it work >.< |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment