Sep 9, 2015 at 4:41pm UTC
Hey guys it's me again ;-)
Today I've got a little prob with CopyFile()
CopyFile(TEXT("../Datalogger/Install/Install/vcredist_x64.exe" ),TEXT("C:/DataLogger/vcredist_x64.exe" ), false );
This code works fine for me as it copies the file correctly.
Now I was thinking about something to check if the file excists.
Is there a way like
1 2 3 4 5 6 7 8
if (CopyFile(TEXT("../Datalogger/Install/Install/vcredist_x64.exe" ),TEXT("C:/DataLogger/vcredist_x64.exe" ), true ))
{
printf ("ERROR" );
}
else
{
printf("done" );
}
?
At the moment it just doesn't copy at all when I use the if-loop.
Or do I have to go the way via fopen() first to check?
Cheers.
Last edited on Sep 9, 2015 at 4:44pm UTC
Sep 9, 2015 at 5:07pm UTC
Last edited on Sep 9, 2015 at 5:11pm UTC
Sep 9, 2015 at 5:13pm UTC
I would check to see if the file exist using normal method, if yes, then call copyfile.
Sep 9, 2015 at 5:50pm UTC
What do you mean "can't use it"? What is preventing you from checking the return value?
Sep 9, 2015 at 5:58pm UTC
If the file does not exist, of course it fails.
There is a return error code, your not using it.
The program continues because you haven't told it to do something else.
IMO the best way is to see if the file exist before you try and copy like you did.
Last edited on Sep 9, 2015 at 6:00pm UTC
Sep 9, 2015 at 6:16pm UTC
Ah ok...so I guess I have to use GetLastError() in this case?!
But I also think that checking the file before try to copy it is the best solution.
Last edited on Sep 9, 2015 at 6:17pm UTC
Sep 9, 2015 at 6:47pm UTC
It is not. The `CopyFile()' function already does that.
"fails" means do nothing and return false (telling the user that it did nothing)
Last edited on Sep 9, 2015 at 6:48pm UTC
Sep 11, 2015 at 3:41am UTC
If that's what the CopyFile() function does, then I would agree.
Maybe ne555 can show us how to display an error msg if the file does not exist.