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

How can I close ONE Low Level file if I don't know the Handle Number 1

Status
Not open for further replies.

LeonelSanchezJr

Programmer
Jan 26, 2001
522
US
Sometimes a low level file will remain open. How can I close just that one low level file without closing all of them?
 
Since I assuming you don't want to issue a CLOSE ALL, the only thing I can thing of is to do the following:

DISPLAY STATUS TO FILENAME myfile.txt NOCONSOLE

Next parse through this text file looking for &quot;User-opened files:&quot; (or whatever your version of VFP says - I'm using VFP 6 SP5). Next you'll have a list of the low-level opened files with their info including &quot;handle=&quot;. (This has been made much easier with VFP 6.0's FILETOSTR() function, although you could use LL IO to read it <g>.)

You'll probably want to remove the .TXT file also.

Rick
 
Great idea, but how can I parse through the text file.

I am using VFP 6. SP5 also.
 
While a little &quot;wordy&quot;, this should give you some ideas:

Code:
** Open a file for testing routine

lcFileName=UPPER(SYS(5)+curdir()+&quot;abc.txt&quot;) && fully qualified
= FOPEN(lcFileName)
****

** Now Close 'lcFileName' if found open **

lcTempFile = sys(2015)+&quot;.txt&quot; && unique name for no conflict
DISPLAY STATUS TO FILE (lcTempFile) NOCONSOLE

lcString = UPPER(FILETOSTR(lcTempFile))

lnOffset = AT(&quot;USER-OPENED FILES:&quot;, lcString)
IF lnOffset > 0 && Got at least one open
   lcUserInfo = SUBSTR(lcString, lnOffset+20)
   lnOffset = AT(lcFileName, lcUserInfo)
   IF lnOffset > 0 && Found Target
      lcFileInfo = SUBSTR(lcUserInfo, lnOffset+LEN(lcFileName))
      lnOffset = AT(chr(13), lcFileInfo) && find EOL
      IF lnOffset > 0 && just look in this line
         lcFileInfo = LEFT(lcFileInfo, lnOffset-1)
      ENDIF
      lnOffset = AT(&quot;HANDLE=&quot;, lcFileInfo)
      IF lnOffset > 0 && now get value
         lnHandle = INT(VAL(SUBSTR(lcFileInfo, lnOffset+7)))
         IF lnHandle > 0
            = FCLOSE(lnHandle)
            MESSAGEBOX(&quot;Closed '&quot;+lcFileName ;
              +&quot;' with Handle of &quot;+TRANSFORM(lnHandle))
         ENDIF
      ELSE
         MESSAGEBOX(lcFileName+&quot; is not Open in this program&quot;)
      ENDIF
   ELSE
      MESSAGEBOX(lcFileName+&quot; is not Open in this program&quot;)
   ENDIF
ELSE
   MESSAGEBOX(&quot;No Low-Level Files Open&quot;)
ENDIF

DELETE FILE (lcTempFile)

**

Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top