Purpose |
Rapidly scan a file opened for INPUT or BINARY mode, in order to obtain size information about variable length string data. |
Syntax |
FILESCAN [#] fnum&, RECORDS TO y& [, WIDTH TO x&] |
Remarks |
FILESCAN assigns a count of the lines/records/strings to y&, and if the WIDTH clause is specified, the length of the longest string to x&. In INPUT mode, it is assumed the data is standard text, with lines delimited by a CR/LF ($CRLF) pair. FILESCAN stops reading the file if it encounters an "end of file" (EOF) marker byte (CHR$(26) or $EOF). Text that occurs after the last CR/LF but before the EOF is considered the last record of the file. Use the LINE INPUT# statement to read a complete text file into an array. In BINARY mode, it is assumed the file was written in the PowerBASIC and/or VB packed string format using PUT of an entire string array. If a string is shorter than 65535 bytes, a 2-byte length WORD is followed by the string data. If a string is equal to or longer than 65535 bytes, a 2-byte value of 65535 is followed by a length DWORD value, then finally the string data. Use the GET statement to read a complete binary file into an array. |
Restrictions |
If FILESCAN is applied to other file formats, the results are undefined. |
See also |
GET, GET$, LINE INPUT#, PUT, PUT$ |
Example |
OPEN "datafile.dat" FOR INPUT AS #1 FILESCAN #1, RECORDS TO count& DIM TheData(1 TO count&) AS STRING LINE INPUT #1, TheData() TO count& CLOSE #1 |
Result |
The entire text file comprising y& lines is read into the string array. |