CopyFile inexplicably fails to work
From: intermedia International Inc (intermedia_at_intermediainternational.com)
Date: 01/23/04
- Next message: Michael W. Diebold: "Re: Problem with W2k, Adobe and shellexecute HELP"
- Previous message: Jeremy Collins: "Re: WinExecAndWaitV2, ok but a question:"
- Next in thread: Peter Below (TeamB): "Re: CopyFile inexplicably fails to work"
- Reply: Peter Below (TeamB): "Re: CopyFile inexplicably fails to work"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 23 Jan 2004 09:49:55 -0600
Hi
I have an application (windows-based) running on machine A.This
application needs to copy files from windows machine B to windows
machine C.
I need to do that from 2 forms - copy single file and copy multiple
files (loop going through a list, one file at a time) .
I have a Utility Unit containing various central procedures & functions,
including the one below, for actually getting Windows to execute the
copy command.
When I call this function from the single file copy form, it works, but
not when called from the multiple file copy form. These tests are run
from the same application, during the same run. The error is 'The path
could not be found for '\\servername\dir\dir\filename.ext'
I made sure that my tests, in all cases, were attempting to copy the
same file from the same directory on the same source PC to the same
filename, in the same target directory on the same target PC. I checked
the filenames , both source name and target name, as I change the name
of the file (full path, including server name), they match across all
the tests.
You will notice that I check for the file's existence in the target
dorectory before copying. This works, that is, the file is correctly
detected in the target directory when is exists already. So the path I
use is correct.
I even re-created the multi file copy form from scratch, the file copy
still does not work.
Any suggestions about the problem or an avenue for testing/debugging?
Your help is appreciated
Jean-Rene
Function CopyFileToServer(SourceFile: string;
DestinationFile: String
) : Integer;{0=general failure, 1=success,
-2=copy failed, 2=file already exists}
var ErrorMessage: pointer; {holds a system error string}
GW_ErrorCode: DWORD; {holds a system error code}
TempVar: TWIN32FindData;
searchHandle: THandle;
begin
CopyFileToServer := 0; {Preset as failed}
// Make sure the file does not already exist
if NOT FileExists(DestinationFile) then
begin
searchHandle := FindFirstFile(PChar(SourceFile),TempVar);
if searchHandle <> ERROR_INVALID_HANDLE then
begin // so far, we found the file
if not CopyFile(PChar(SourceFile),PChar(DestinationFile),FALSE)
then
begin // Problem copying the file - inform the user then exit
{GW_ErrorCode := GetLastError;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
or FORMAT_MESSAGE_FROM_SYSTEM,
nil,GW_ErrorCode,0,@ErrorMessage,0,nil);
MessageDlg(string(PChar(ErrorMessage)) + 'For: '+
DestinationFile +
#13#10 +
'Click OK to continue',mtError,[mbOK],0); }
CopyFileToServer := -2; // Failure to copy file to server
Exit;
end
else
begin
//ShowMessage('File uploaded successfully!');
CopyFileToServer := 1; // Success
end; //if not CopyFile(...
end; //if searchHandle <>
end
else
begin // Ths file exists already
CopyFileToServer := 2 ; // success, but, upon returning, signal that
the file was already there
// as it may matter to the spot where this
function was called from
end; // if NOT FileExists(sDestinationFile)
end; {Function CopyFileToServer}
- Next message: Michael W. Diebold: "Re: Problem with W2k, Adobe and shellexecute HELP"
- Previous message: Jeremy Collins: "Re: WinExecAndWaitV2, ok but a question:"
- Next in thread: Peter Below (TeamB): "Re: CopyFile inexplicably fails to work"
- Reply: Peter Below (TeamB): "Re: CopyFile inexplicably fails to work"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|