Lazarus

Free Pascal => Beginners => Topic started by: Birger52 on November 18, 2019, 07:49:38 pm

Title: Copy File
Post by: Birger52 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?
Title: Re: Copy File
Post by: winni 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
Title: Re: Copy File
Post by: Birger52 on November 18, 2019, 11:27:00 pm
Thx. Will try that.
Didn't know that was an option... https://wiki.freepascal.org/CopyFile
Title: Re: Copy File
Post by: Birger52 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;
TinyPortal © 2005-2018