Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to detect if a file is in use

Status
Not open for further replies.

thomascd

Programmer
Mar 20, 2002
29
0
0
GB
Hi is there a quick way too detect if a file is in use by any user ? (any kind of file, not foxpro tables)
 
Use fopen.. it will return a negative number if file is in use....

JF
 
thomascd

I guess it depends on the kind of file. Some files can be opened with FOPEN() some need to be open with the actual program they are associated with. But in most cases if you are trying to open a file that is already opened by another user VFP will throw an error that you can trap. Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Another way to find out if a file is in use is to try to rename it to itself, like:

RENAME myfile.dat TO myfile.dat

If VFP returns an error then the file is in use. I use this method when copying customer files from an FTP site by an automated process. Some files are rather large and my automated script runs every 15 minutes. If it can rename the file to itself, then the file is copied. If it can't, then it sleeps for 15 minutes and tries again.

Steve
 
However, what if someone opens a file in the moment between checking if it's in use, and when you actually start trying to use it?

Better will be VFP8's TRY..CATCH error handling.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top