Error While using the CopyFile function

Nalu picture Nalu · Aug 9, 2012 · Viewed 16.1k times · Source

Hello I am using the CopyFile function in Delphi 5. But the file is not getting copied to destination. I am not able to see error also. What is the best way to know why CopyFile is failing?

if CopyFile(source, dest, false) then
  ShowMessage('Success')
else
  ShowMessage('Error');

I am getting displayed error always. :(

Answer

RRUZ picture RRUZ · Aug 9, 2012

If the function fails you can get extended error information, calling the GetLastError method or use the RaiseLastOSError method.

Check this sample

  try
    If copyFile(source , dest,false) then
     ShowMessage('Success')
    else
     RaiseLastOSError;
  except  on E: Exception do
     showMessage(Format('Error executing copyFile %s',[E.Message]));
  end;