Topic: How to overwrite an existing file

hi,
How to create a folder and overwrite an existing file with script? Example below only works if the file does not exist.

procedure Form1_btBackup_OnClick (Sender: string; var Cancel: boolean);
begin
          if 7 = MessageDlg('Create / Update the SqLiteDB? Best choice is every day on the end of the shift back it up.', mtConfirmation, mbYes + mbNo, 0) then
          begin
                Cancel := True;  // I think it is not necessary
                CopyFile('sqlite.db', 'Backup\sqlite.db'); // Application path
                //CopyFile('sqlite.db', 'I:\TP2014\Backup\sqlite.db'); // Reserve path
                //P:\C\CF\CF3\TEST GA en MB\TP2014\Backup\sqlite.db  // Backup path workplace
          end;
end;

Thanks

Re: How to overwrite an existing file

Hello,


if the file "Backup\sqlite.db" already exists, the function (CopyFile) overwrites the existing file.



Can you send me your project for test?
support@drive-software.com



Thanks.

Dmitry.

Re: How to overwrite an existing file

Hi again,

I remove this code and the copyfile function work well.

Cancel := True;  // I think it is not necessary

Thanks

Re: How to overwrite an existing file

I think a command Cancel:= true; stops script executing after itself.
otherwise there would be no sense in this command

Re: How to overwrite an existing file

Hi,
I change script to

Cancel := False;

the function (CopyFile) overwrites the existing file correct now.

Thanks

Re: How to overwrite an existing file

No need Cancel := False; in code.

Dmitry.

Re: How to overwrite an existing file

what for? Cancel is a default value

Re: How to overwrite an existing file

Hi again,

You are right, the Cancel function in this case is unnecessary.

Thanks