Reputation: 52519
I'm trying to copy a file from one location to another using SHFileOperation:
SHFILEOPSTRUCT fileop;
fileop.hwnd = 0;
fileop.wFunc = FO_COPY;
fileop.pFrom = L"C:\\SomeDirectory\\SomeName.jpg\0";
fileop.pTo = L"C:\\SomeOtherDirectory\\SomeName.jpg\0";
fileop.fFlags = FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT;
fileop.fAnyOperationsAborted = FALSE;
fileop.hNameMappings = 0;
fileop.lpszProgressTitle = 0;
SHFileOperation(&fileop);
The problem is that instead of getting a copy of SomeName.jpg in SomeOtherDirectory an empty directory with name SomeOtherDirectory\SomeName.jpg is created, any clues?
Upvotes: 2
Views: 2040
Reputation: 791849
For FO_COPY
and FO_MOVE
operations the pTo
member of the SHFILEOPSTRUCT
must be a location, i.e. a directory, and not a destination filename. The directory is allowed not to exist, in which case it is created even if it looks like a filename.
You should either just specify "C:\\SomeOtherDiretory\0"
or use FO_RENAME
.
As to why your file is not created, have you checked the return value?
Upvotes: 1