'How to fix error with SHFileOperationA when I am trying to copy a directory from a remote drive to a new directory on that same drive. WinSysErr 183
When I am using this method on my local drive it will work as intended and copy my intended directory(With two files inside) to another location on my local drive.
However, when trying to do the same thing on a remote drive, I receive an error code from SHFileOperationA( &directory ); Specifically 183, which looking at Windows System Errors I find this:
ERROR_ALREADY_EXISTS183 (0xB7) Cannot create a file when that file already exists.
Any ideas on what could be causing this issue? I know that there is no file/folder restriction on this Q: drive because I am able to create directories, and because of this, I am sure that the path names are correct also.
void Utilities::CopyDirectory(CString from, CString to)
{
SHFILEOPSTRUCTA directory;
/////////////////////////////////test strings
////////////////////////////////from = "Q:\\TestFolder"
////////////////////////////////to = "Q:\\A\\B"
char fromDir[100];
char toDir[100];
strcpy(fromDir, from);
strcpy(toDir, to);
//Last file name is terminated with a double NULL character to indicate end of buffer
//add null character after the last single NULL
fromDir[strlen(fromDir) +1] = 0;
toDir[strlen(toDir) +1] = 0;
directory.hwnd = NULL;
directory.wFunc = FO_COPY;
directory.pFrom = fromDir;
directory.pTo = toDir;
directory.fFlags = FOF_RENAMEONCOLLISION | FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR | FOF_SILENT;
directory.fAnyOperationsAborted = 0;
directory.hNameMappings = NULL;
directory.lpszProgressTitle = NULL;
int i = SHFileOperationA( &directory );
//i = 0 if success. If not Windows System Error Code
if(i != 0)
{
sprintf(gBuf, "Error Occured in copying temp directory to: \n%s\n\n WinSysErrCode: %d", to, i);
::MessageBox(NULL, gBuf, "Directory Copy To Outbox Error", MB_OK);
DeleteDirectory(from);
return;
}
//Delete temporary outbox folder after it was sent to Outbox
DeleteDirectory(from);
if(from.Find("QPPR_") >= 0)
{
sprintf(gBuf, "Receipt has been sent to the email server outbox.\n\nSent to: %s", to);
::MessageBox(NULL, gBuf, "Email Sent", MB_OK);
}
else if(from.Find("QPP_") >= 0)
{
sprintf(gBuf, "Pay Now Request has been sent to the email server outbox.\n\nSent to: %s", to);
::MessageBox(NULL, gBuf, "Email Sent", MB_OK);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
