How to Determine the Number of Files Currently OpenLast reviewed: November 21, 1995Article ID: Q119352 |
The information in this article applies to:
SUMMARYAlthough the SYS(2010) function can be used in FoxPro for MS-DOS to return the maximum number of files specified in the CONFIG.SYS file (in FoxPro for Windows, this function always returns 255), there is no function that will return the number of files currently in use within the current FoxPro session. The user-defined function (UDF) shown below will return the number of files open within the current FoxPro session at the time the function is called.
MORE INFORMATIONCreate the function OPEND() as either a separate .PRG file or as a FUNCTION subroutine in the program that calls it. In this example, it is used as a FUNCTION subroutine within a file named FYLCOUNT.PRG:
* FYLCOUNT.PRG program file, containing the UDF Opend * x = OPEND() WAIT WINDOW "There are currently "+ALLTRIM(STR(x))+" files opened." FUNCTION opend SET TEXTMERGE TO SYS(2015) && open a temporary text file cnt=_TEXT-1 && subtract 1 from its handle SET TEXTMERGE TO && close the temporary file RETURN cnt && send back the number of filesWhen the program is run, the file handle for the temporary text merge file is allocated (an error will be generated if not enough handles are available). This handle is stored in the system variable _TEXT. Because the current count is desired, 1 is subtracted from the number in _TEXT to eliminate the temporary text file from being included in the count of open file handles. This result is stored in the variable "cnt". The temporary file is closed, returning the file handle it used to the remaining file handles available. As nothing was written to the file, the filename was not written to the disk directory, and thus requires no maintenance to remove it from disk.
|
Additional reference words: FoxDos FoxWin 2.50 2.50a 2.50b 2.60 fopen
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |