Recent

Author Topic: Copy File  (Read 292 times)

Birger52

  • Full Member
  • ***
  • Posts: 125
Copy File
« on: November 18, 2019, 07:49:38 pm »
Is there any way to determine, what is wrong, when CopyFile doesn't copy the file, it is asked to?

winni

  • Hero Member
  • *****
  • Posts: 590
Re: Copy File
« Reply #1 on: November 18, 2019, 08:18:24 pm »
Hi!

Assuming you mean copyfile in fileutis (and not the other definitions in Jedi, IDE, .....) the
syntax gives you the answer:

function CopyFile(const SrcFilename, DestFilename: string; PreserveTime: boolean; ExceptionOnError: Boolean=False): boolean;

So just set ExceptionOnError to true and look at the text of the exception.
It will tell you.

So do a

Code: Pascal  [Select]
  1. if CopyFile (MySrc, MyDest, true, true) then ......


Winni

Birger52

  • Full Member
  • ***
  • Posts: 125
Re: Copy File
« Reply #2 on: November 18, 2019, 11:27:00 pm »
Thx. Will try that.
Didn't know that was an option... https://wiki.freepascal.org/CopyFile

Birger52

  • Full Member
  • ***
  • Posts: 125
Re: Copy File
« Reply #3 on: November 19, 2019, 12:41:05 am »
Works like a charm. ;)

And actually
Code: Pascal  [Select]
  1. function CopyFile(const SrcFilename, DestFilename: string; Flags: TCopyFileFlags=[cffOverwriteFile]; ExceptionOnError: Boolean=False): boolean;
  2. // Since I both need to preserve dates and overwrite existing..
  3. try
  4.   CopyFile(oName, bName, [cffPreserveTime, cffOverwriteFile], true);
  5. except
  6.   on E: Exception do Msg.DispMsg(E.message, mtErr);
  7. end;