🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.delphi.nativeapi
Article #105

CopyFile inexplicably fails to work

#105
From: intermedia International Inc
Date: Fri, 23 Jan 2004 15:49
79 lines
4244 bytes
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}
Technical Details
Message-ID: <401142A3.21F96215@intermediainternational.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f94dd,89f023344b899a85,start
X-Google-Attributes: gidf94dd,public
X-Google-ArrivalTime: 2004-01-23 08:10:21 PST
Message-ID: <401142A3.21F96215@intermediainternational.com>
Date: Fri, 23 Jan 2004 09:49:55 -0600
From: intermedia International Inc <intermedia@intermediainternational.com>
X-Mailer: Mozilla 4.7 [en] (WinNT; I)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: borland.public.delphi.nativeapi
Subject: CopyFile inexplicably fails to work
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 209.5.247.139
X-Trace: newsgroups.borland.com 1074872615 209.5.247.139 (23 Jan 2004 07:43:35 -0700)
Lines: 81
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail