Recent

Author Topic: Copy File  (Read 1186 times)

Birger52

  • Sr. Member
  • ****
  • Posts: 309
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?
Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

winni

  • Hero Member
  • *****
  • Posts: 3197
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

  • Sr. Member
  • ****
  • Posts: 309
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
Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

Birger52

  • Sr. Member
  • ****
  • Posts: 309
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;
Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

 

TinyPortal © 2005-2018