[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How can I test if a file is locked?

Posted on 2009-04-22
4
Medium Priority
?
163 Views
Last Modified: 2012-05-06
Hello guys

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

Thanks
0
Comment
Question by:hidrau
  • 2
  • 2
4 Comments
 
LVL 4

Expert Comment

by:JDominguezNY
ID: 24209044
You can use an application like OpenedFilesView to check.

http://www.nirsoft.net/utils/opened_files_view.html
0
 
LVL 4

Accepted Solution

by:
JDominguezNY earned 2000 total points
ID: 24209097
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
 
LVL 1

Author Closing Comment

by:hidrau
ID: 31573502
Wonderful function
Thanks very much
0
 
LVL 1

Author Comment

by:hidrau
ID: 24209499
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

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Screencast - Getting to Know the Pipeline
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question