Re: is a file being used by another program?

Posted by Jenny on May 01, 2007

In Reply to if a file is being used by another program posted by wizard_pm on April 20, 2007

: How can I find out if a specific file (such as D:\common.txt) is being used by another program?

There is no Delphi function that tells you if a file is "in use" (or "open", "locked").

There's a lot of confusion about these terms. It can mean that a program "locked" a file for quite some time (but it still can be read by others), as to prevent other programs from writing to it until it is "unlocked". Or it can be locked entirely for reading as well as writing. The locking can be done by Windows itself, and then you can detect it with certain Windows API functions. But with most database systems, it's the application itself that writes a temporary "lock file" somewhere, so Windows is unaware of this.

Text files: usually when an "editor" program loads a text file and makes its contents visible on screen, such as with Windows' own NotePad, it does not "lock" the file when you open it. The file is locked only for a few milliseconds at the moment of saving it after changes. As a consequence, you can not detect from your program if a text file is "open" in such an editor.

Related articles

Files that are "open"
How can I tell if a file is "open"?
     

Follow Ups