Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


ID: 23135, Howto check if file is locked by another program

by Aliaksei Sporyk Email: Anonymous


Sometimes file in Windows is not accesible because of another program.
To check this lock i create two simple functions.
Download Details
FTP  download also available 0 bytes
CDN Login Required to Download. (You will be redirected to the login page if you click on the Download Link)
To download this, you must have registered:
A free membership

For Delphi, Version 1.0  to 1.0 1 download
Copyright: Open Source or other


Size: 0 bytes
Updated on Wed, 06 Apr 2005 02:13:41 GMT
Originally uploaded on Wed, 06 Apr 2005 02:15:23 GMT
Description
Sometimes file in Windows is not accesible because of another program.
To check this lock i create two simple functions.

function IsItLocked(FileName: TFileName): Boolean;
var h:THandle;
begin
h:=windows.CreateFile(PChar(FileName),GENERIC_READ or GENERIC_WRITE,0,nil,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
Result:=h=INVALID_HANDLE_VALUE;
if not Result then CloseHandle(h);
end;

function IsItLockedRead(FileName: TFileName): Boolean;
var h:THandle;
begin
h:=windows.CreateFile(PChar(FileName),GENERIC_READ,FILE_SHARE_READ,nil,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
Result:=h=INVALID_HANDLE_VALUE;
if not Result then CloseHandle(h);
end;

   Latest Comments  View All Add New

Move mouse over comment to see the full text

Could not retrieve comments. Please try again later.

Server Response from: ETNACDC04