tags:

views:

37

answers:

1

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?

A: 

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?

Charles Bailey
But MSDN(http://msdn.microsoft.com/en-us/library/bb759795%28VS.85%29.aspx) says `pTo` is *A pointer to the destination file or directory name*.
Naveen
@Naveen: you have to read the documentation for `wFunc` as well to see how it is used.
Charles Bailey