How to trap error from CopyFile command? lazarus / 61-Beginners ---------------------------------------------------------------------- bulrush · 2016-06-23 15:58 I'm getting an error from the CopyFile command but how do I trap that error? Here's the code I have. If the 2 filenames are the same I don't want to copy them, otherwise copy from p1 to p2. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     if (p1 <> p2) then      If (not CopyFile(Pchar(p1), Pchar(p2), True)) then      begin        s:=procname+' ERROR: Could not copy from '+p1+' to '+p2;        writeerr(s);        myexit();        end      else        writeerr(procname+': Copied image from '+p1+' to '+p2);      end; //if reimg.exec(s)  Thanks! ---------------------------------------------------------------------- molly · 2016-06-23 17:03 I seem to misunderstand what you meant by 'how do i trap that error'. You already do that by providing bFailIfExists. You can use GetLastError() to obtain the reason for failure. For documentation regarding windows copyfile() function see msdn Maybe an idea to use lazarus copyfile() function ? That function you should be able to 'trap' by enclosing it in a try except block. ---------------------------------------------------------------------- bulrush · 2016-06-30 13:18 Sorry, I meant I'm looking for the operating system error, or the reason the copy failed. If you look at the error message in the ELSE statement, it does now show the OS error, which is what I'm looking for, it just shows a generic error message. I want a more specific error message, the reason why the copy failed, not just that the copy failed. ---------------------------------------------------------------------- bulrush · 2016-06-30 13:27 It looks like GetLastError returns a LONGWORD. How do I get the actual text of the error? ---------------------------------------------------------------------- Bart · 2016-06-30 16:25 Quote from: bulrush on June 30, 2016, 03:27:11 pmIt looks like GetLastError returns a LONGWORD. How do I get the actual text of the error? SysErrorMessage(GetLastOSError). Bart