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?
For
FO_COPYandFO_MOVEoperations thepTomember of theSHFILEOPSTRUCTmust 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 useFO_RENAME.As to why your file is not created, have you checked the return value?