Weird ::CopyFile problem
-
I have an application that upon startup does an automatic software update. It checks a folder if it contains any files, and if found, copies those files over to their respective target folders. Now suddenly this updating does not work anymore. It copies the file to the target folder, but the result is not a file in the target folder, but a sub folder with it's name as the source file's name. Ex. I have a file in my upgrade folder: C:\Program\Upg\Logo.jpg This file needs to be copied to C:\Program So my program does CopyFile(strSource, strTarget, FALSE) with strSource = "C:\\Program\\Upg\\Logo.jpg" strTarget = "C:\\Program\\Logo.jpg" After the copy I end up with a sub-folder in C:\Program called Logo.jpg\ which is empty, instead of a file called Logo.jpg in C:\Program I then hard coded the paths like: CopyFile("C:\\Program\\Upg\\Logo.jpg", "C:\\Program\\Logo.jpg", FALSE); but it does exactly the same I then made an empty new console application with the hard coded CopyFile call as above and it works fine, ie. Logo.jpg is copied from the Upg folder to C:\Program I tried playing with the project settings, stack/heap sizes, etc, but my application does not copy the file ! Any ideas ?
-
I have an application that upon startup does an automatic software update. It checks a folder if it contains any files, and if found, copies those files over to their respective target folders. Now suddenly this updating does not work anymore. It copies the file to the target folder, but the result is not a file in the target folder, but a sub folder with it's name as the source file's name. Ex. I have a file in my upgrade folder: C:\Program\Upg\Logo.jpg This file needs to be copied to C:\Program So my program does CopyFile(strSource, strTarget, FALSE) with strSource = "C:\\Program\\Upg\\Logo.jpg" strTarget = "C:\\Program\\Logo.jpg" After the copy I end up with a sub-folder in C:\Program called Logo.jpg\ which is empty, instead of a file called Logo.jpg in C:\Program I then hard coded the paths like: CopyFile("C:\\Program\\Upg\\Logo.jpg", "C:\\Program\\Logo.jpg", FALSE); but it does exactly the same I then made an empty new console application with the hard coded CopyFile call as above and it works fine, ie. Logo.jpg is copied from the Upg folder to C:\Program I tried playing with the project settings, stack/heap sizes, etc, but my application does not copy the file ! Any ideas ?
is your CopyFile return true or false?? If false than use GetLastError() to check the error information.
"Every Little Smile can touch Somebody's Heart... May we find Hundreds of Reasons to Smile Everyday... and May WE be the Reason for someone else to smile always!" (ICAN) "Your thoughts are the architects of your destiny."
-
is your CopyFile return true or false?? If false than use GetLastError() to check the error information.
"Every Little Smile can touch Somebody's Heart... May we find Hundreds of Reasons to Smile Everyday... and May WE be the Reason for someone else to smile always!" (ICAN) "Your thoughts are the architects of your destiny."
It sometimes returns TRUE , but still copies the file into the empty sub-folder It sometimes returns FALSE, but still copies the file into the empty sub-folder, GetLastError then returns 5
-
is your CopyFile return true or false?? If false than use GetLastError() to check the error information.
"Every Little Smile can touch Somebody's Heart... May we find Hundreds of Reasons to Smile Everyday... and May WE be the Reason for someone else to smile always!" (ICAN) "Your thoughts are the architects of your destiny."
I have now also tried SHFileOperation as follows, but it also copies the file into the sub folder : SHFILEOPSTRUCT sMove = {GetSafeHwnd(), FO_MOVE}; sMove.pFrom = strSource + _T("\0"); sMove.pTo = strTarget + _T("\0"); sMove.fFlags = FOF_NO_UI; SHFileOperation(&sMove);
-
It sometimes returns TRUE , but still copies the file into the empty sub-folder It sometimes returns FALSE, but still copies the file into the empty sub-folder, GetLastError then returns 5
od@ananzi.co.za wrote:
It sometimes returns TRUE , but still copies the file into the empty sub-folder
It sometimes returns FALSE, but still copies the file into the empty sub-folder, GetLastError then returns 5:confused: If GetLastError returns 5 than it means Access Denied. You do not have rights to copy data in Program folder. 1) Run your application as admin or 2) Change the property "UAC Execution Level" -> "asInvoker" to "requireAdministrator".
"Every Little Smile can touch Somebody's Heart... May we find Hundreds of Reasons to Smile Everyday... and May WE be the Reason for someone else to smile always!" (ICAN) "Your thoughts are the architects of your destiny."
-
od@ananzi.co.za wrote:
It sometimes returns TRUE , but still copies the file into the empty sub-folder
It sometimes returns FALSE, but still copies the file into the empty sub-folder, GetLastError then returns 5:confused: If GetLastError returns 5 than it means Access Denied. You do not have rights to copy data in Program folder. 1) Run your application as admin or 2) Change the property "UAC Execution Level" -> "asInvoker" to "requireAdministrator".
"Every Little Smile can touch Somebody's Heart... May we find Hundreds of Reasons to Smile Everyday... and May WE be the Reason for someone else to smile always!" (ICAN) "Your thoughts are the architects of your destiny."
It made no difference. I also tried running the program as Administrator, but still the same. Remember that my console application worked fine though, so I doubt that it is permissions ...
-
It made no difference. I also tried running the program as Administrator, but still the same. Remember that my console application worked fine though, so I doubt that it is permissions ...
Error code 5 means access denied. I am not sure why this error comes. I don't know it is working or not but before copying the file into the target file, Delete the target file using "DeleteFile".
DeleteFile(strTargetPath); CopyFile(strSourcePath,strTargetPath,FALSE);
"Every Little Smile can touch Somebody's Heart... May we find Hundreds of Reasons to Smile Everyday... and May WE be the Reason for someone else to smile always!" (ICAN) "Your thoughts are the architects of your destiny."
-
It made no difference. I also tried running the program as Administrator, but still the same. Remember that my console application worked fine though, so I doubt that it is permissions ...