FindFirst
Function FindFirst( filespec [, attributes] )
Returns a string which is the name of the first file that matches filespec.
Syntax a = FindFirst("*.txt")
Remarks
FindFirst sets up the structures necessary to make repeated calls to the related FindNext function.
FindFirst also returns the first filename that matches Filespec.
If there are no files that match filespec or that have the same attributes as described in attributes then FindFirst returns the empty string " ".
The optional attributes parameter to FindFirst is a number that is the sum of the following values:
to return Read-only files add 1
to return Hidden files add 2
to return System files add 4
to return Volume ID files add 8
to return Directories add 16
to return files with the archive bit set add 32
to return all files (including directories) add 63
See the example script for an example of using these flags.
If the optional attribute flag is not given then all files (excluding directories) will be returned.
Notes: Just because a filename appears in a FindFirst / FindNext call, does not imply that it is available to be read or written. Files that are open by other processes, are read-only, etc. May be listed, but for other reasons cannot be opened.
See Also:
FindNext File and Directory functions
Example Script 1
NUMBER x
STRING a,b = "C:\*.*"
a = FINDFIRST(b,1 + 2 + 4) ' retrieve read-only, hidden, system files
WHILE LEN(a)
x ++
a = FINDNEXT()
WEND
PRINT "There are "; x; " read-only, hidden, system files in c:\"
Script Output
(your results maybe different)
There are 27 read-only, hidden, system files in c:\
- - - -
Example Script 2
NUMBER x
STRING a,b
a = CWD()
IF MID(a,LEN(a),1) <> "\" THEN
a = a + "\"
ENDIF
b = a + "*.txt"
a = FINDFIRST(b) ' retrieve matching files in the current working directory.
WHILE LEN(a)
IF FOPEN(1,a) THEN
x ++
PRINT "The first line from "; a; " is: ";
PRINT FGETS(1)
FCLOSE(1)
ENDIF
a = FINDNEXT()
WEND
Script Output
(your results maybe different)
The first line from CHDIR.txt is: IF CHDIR("C:\Temp") THEN
The first line from CHR.txt is: NUMBER i,j
The first line from COS.txt is: NUMBER i = 0
The first line from CWD.txt is: STRING a
The first line from EXP.txt is: NUMBER e
The first line from EXP10.txt is: ' Let's check the first 5 powers of 10
The first line from EXP2.txt is: ' Let's enumerate the powers of 2 from 0 to 7
The first line from ABS.txt is: NUMBER i
The first line from ACOS.txt is: NUMBER pi = 3.141592654
The first line from ASC.txt is: STRING a = "Hello"
The first line from ASIN.txt is: NUMBER pi = 3.141592654
The first line from ATN.txt is: NUMBER i = 45
The first line from FCLOSE.txt is: NUMBER x = 1,i
The first line from FCLOSEALL.txt is: NUMBER x = 1,i
The first line from FEOF.txt is: NUMBER x = 1
The first line from FGETC.txt is: NUMBER x = 1
The first line from FGETS.txt is: NUMBER x = 1
The first line from FILEEXISTS.txt is: STRING a = "*.txt"
The first line from FILELEN.txt is: STRING a
The first line from FINDFIRST Example 1.txt is: NUMBER x
The first line from FINDFIRST Example 2.txt is: NUMBER x