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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to check if LL file is open?

Status
Not open for further replies.

wilfranz

Technical User
Oct 4, 2003
122
US
Hello friends,

How can I determine if a low-level file is open? I'm looking for a function which would be analgous to the USED("TableName") function for db tables.

The situtation: I am reading a low-level binary file and need a means to know if the file has been previously opened (with FOPEN) and if it now remains open. And if it is, I need to get its FileHandle (the one assigned by FP), to either close it or access it again.

TIA

wilfranz
 
wilfranz

If you try to open a file using FOPEN() twice, the second time the handle returns - 1
nHandle =FOPEN("c:\text.txt")
? nHandle && Return 20
nHandle =FOPEN("c:\text.txt")
? nHandle && Return -1



Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Thanks for your response, Mike.

I guess your answer tells me that there is no direct function for this.

I don't think I can infer that a file is already open with only a FileHandle return of -1, because, as I understand it, the -1 means only that VFP was "unable to open" the file. So it could also mean that it doesn't exist, or is on another directory, or is in use by another application, etc.

Also, if it IS open, I need to know the already-existent FileHandle so as to use it.

If there is no native function for this, I guess I could write my own by writing the DISPLAY STATUS TO [file], then reading that Status.txt file to search for the possibly-open target file, and then, if it is open (i.e. listed), read the FileHandle number, which is listed on the same line. But whew!, I hoped VFP might do that for me.

Thanks again... at least, for letting me know not to search vainly for the grail.

wilfranz
 
wilfranz,

Would it not be possible to keep track of the open file handles yourself in an array/collection?

I guess I could write my own by writing the DISPLAY STATUS TO [file]...

This is the only way I know how to do it if you have no idea what the handle is.

Andy
 
wilfranz,

George Tasker has written a function called is_run, that determines if a Windows application is already running by the known portion of the title bar. This function returns the window handle.

This file(ID#9292) is available at universalthread.com.
 
wilfranz,
Actually, while there isn't one built-in, you could create one. If you LIST STATUS to a FILE, you could then parse the file for the "User-opened files:" and pick off the LL opened files (and some additional info if you want it!).

Rick
 
Thanks for your post, Rick.

Yes, I had mentioned that route in my first reply to MGagnon (3rd item in this thread). And it looks like that's what I'll end up doing. Parsing the STATUS report will also provide the FileHandle assigned by VFP.

I had just been hoping there was a native function like the USED() function.

Thanks,

Bill

 
Soory Bill,
Sometimes it's easy to overlook a previous "right" answer when you know you've got THE answer.

Glad that great minds think alike! :)

Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top