How can I test if a file is locked?

Hello guys

Is there any way to know if a file is locked? That is, it is being used?

Thanks
LVL 1
hidrauAsked:
Who is Participating?
 
JDominguezNYConnect With a Mentor Commented:
Sorry just noticed your topic was based on delphi,  have a look here:
http://stackoverflow.com/questions/141302/checking-file-is-open-in-delphi
0
 
JDominguezNYCommented:
You can use an application like OpenedFilesView to check.

http://www.nirsoft.net/utils/opened_files_view.html
0
 
hidrauAuthor Commented:
Wonderful function
Thanks very much
0
 
hidrauAuthor Commented:
This function is from the link


function IsFileInUse(fName : string) : boolean;
var HFileRes : HFILE;
begin
  Result := False;
  if not FileExists(fName) then
    Exit;
  HFileRes := CreateFile(pchar(fName),
                         GENERIC_READ or GENERIC_WRITE,
                         0, nil, OPEN_EXISTING,
                         FILE_ATTRIBUTE_NORMAL, 0);
  Result := (HFileRes = INVALID_HANDLE_VALUE);
  if not Result then
    CloseHandle(HFileRes);
end;

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.