You could try and Open it with FOPEN(). Since this always opens files "exclusive", if you can't open it, then it must be in use by someone else!
LOCAL llRtnVal as Boolean
LOCAL lnHandle as Number
llRtnVal = TRUE && assume file is closed
lnHandle = FOPEN(tcFileName,F_READWRITE_UNBUFF)
IF lnHandle = F_OPEN_FAILURE
llRtnVal = FALSE && file is open
MESSAGEBOX(ALLTRIM(tcFileName)+' file open by someone else',MB_ICONSTOP))
ENDIF
As the above comments indicate, the only quick way to test to see if a file is open is to attempt to open it exclusively. They are the best and simplest way to determine if a table is open.
Otherwise, you'll have to walk over to the server and look through the server's list of open files, but you can't really trust that list 100%. A good example of that is when a workstation crashes, the files it had open probably are not open any longer, but those links could persist for a while at the server and erroneously indicate it was still open.
I came across a VB script that I converted to VFP that will create a cursor of open files, and who has them open on the server.
Create cursor isopen (f_user c(10), f_path c(30) )
Store 1 to ColumnNumber,RowNumber
LcOfile='.DBF'
** Change MyServer to fit your needs.
fso = GetObject("WinNT://MyServer/LanmanServer"
For Each resource In fso.resources
if type('resource.user')!='C'
exit
endif
If resource.User!= "" or Right(resource.User,1)!= "$"
If occurs(lcOfile, upper(resource.path) )>0 or lcOfile==''
m.f_user = resource.user
m.f_path = resource.Path
insert into isopen from memvar
Endif
Endif
Endfor
select isopen
if reccount()>0
browse
else
messagebox('No Open Files')
endif
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.