CopyFile fails, driving me nuts! lazarus / 31-LCL ---------------------------------------------------------------------- jack · 2012-08-06 01:47 Please give me the benefit of your fresh eyes! I am struggling to see what is wrong with the code below. I get a false return from the line that reads: if(CopyFile(DB1Addr,filename)) then begin I am going blind.  Attached is a watchlist showing what I believe to be Valid paths for the copy.  I have tried many things including moving the files and such. Here is my code: ---------------------------------------------------------------------- ----------------- procedure TForm1.mmBackupClick(Sender: TObject); var filename:string; begin   // Backup Database   dlgSave.Title := 'Select Database Backup Location';   dlgSave.DefaultExt := 'dbk';   dlgSave.Filter:='Backup (*.dbk)';   dlgSave.FileName:='DBPW';   if(dlgSave.Execute) then begin     filename:=dlgSave.FileName;     if(CopyFile(DB1Addr,filename)) then begin      showMessage('Database has been Saved');     end else begin      showMessage('Database Save Failed');     end;   end; end;          ---------------------------------------------------------------------- ---------------------------- Thanks for your help. Jack ---------------------------------------------------------------------- jack · 2012-08-06 03:18 Answer my own question for posterity. Copyfile does not understand long file names! ---------------------------------------------------------------------- bonmario · 2012-08-06 05:14 Some time ago there was a bug: if the dest file already exists, the return was false. Try updating Lazarus. Hi, Mario ---------------------------------------------------------------------- marcov · 2012-08-06 07:29 OS, what do you mean with long filenames \\?\ stuff? ---------------------------------------------------------------------- jack · 2012-08-06 14:01 Here is my middle of the night work around. This seems to work although I am sure that I'll find holes in production. ---------------------------------------------------------------------- function DOSdir(longName:string):string; var dirTo:string; begin   dirTo:=AnsiLeftStr(longName,length(longName)-(length(longName)- LastDelimiter('\',longName))-1);   DOSdir:=ExtractShortPathName(dirTo); end; function DOSFile(longName:string):string; var FileTo:string; begin   fileTo:=AnsiRightStr(longName,(length(longName)- LastDelimiter('\',longName)));   DOSFile:=fileTo; end; procedure TForm1.mmBackupClick(Sender: TObject); var longTo,dirTo,shortFrom,shortTo,test:string; begin   // Backup Database   dlgSave.Title := 'Select Database Backup Location';   dlgSave.DefaultExt := 'dbk';   dlgSave.Filter:='Backup (*.dbk)';   dlgSave.FileName:='DBPW';   dlgSave.Execute;   longTo:=(dlgSave.FileName);   shortTo:=DOSdir(LongTo)+'\'+DOSFile(longTo);   shortFrom:=DOSdir(DB1Addr)+'\'+DOSFile(DB1Addr);    if(CopyFile(PChar(shortFrom),PChar(shortTo),false)) then begin      showMessage('Database has been Saved');    end else begin      showMessage('Database Save Failed');    end;  end; ---------------------------------------------------------------------- bylaardt · 2012-08-06 18:54 use this: copyfileutf8 look this: http://bugs.freepascal.org/view.php?id=19743