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


Determine if a file is open

Posted on 2006-03-28
Medium Priority
Last Modified: 2010-04-05
How can I easily determine if a file is already open before I try to open it programatically.

Specifically, my program involves displaying pdf files in Acrobat Reader.  If the user already has one the pdf file open, how can detect that?

Question by:light_bulb
LVL 18

Accepted Solution

Johnjces earned 200 total points
ID: 16315801
Try this:

function IsFileInUse(FileName: TFileName): Boolean;
  HFileRes: HFILE;
  Result := False;
  if not FileExists(FileName) then Exit;
  HFileRes := CreateFile(PChar(FileName),
                         GENERIC_READ or GENERIC_WRITE,
  Result := (HFileRes = INVALID_HANDLE_VALUE);
  if not Result then
LVL 27

Expert Comment

ID: 16318850
usual a try to open the file exclusive should tell you if you can do this,
if you can -> the file is not in use
if you not can -> the file is use

guess this does the suggestion of  Johnjces already,
it could be done with a TFileStream aslo

meikl ;-)

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
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