The FILES statement collects file and directory information from any disk and/or directory and fills a double-dimensioned array with the information. It is also good for determining if a specific file exists (see below).
Before you use the FILES statement, you must first dimension a double-dimensioned string array for its use. The name of the array is up to you. LB programmers often call this array info$().
dim info$(10, 10) files "c:\", info$()
The above FILES statement will fill info$( ) in this fashion:
info$(0, 0) - a string specifying the qty of files found info$(0, 1) - a string specifying the qty of subdirectories found info$(0, 2) - the drive spec info$(0, 3) - the directory path
Starting at info$(1, x) you will have file information like so:
info$(1, 0) - the file name info$(1, 1) - the file size info$(1, 2) - the file date/time stamp
"info$()" is a string array, so to get numeric values, use the VAL function. The quantity of files found is returned like this:
n = VAL(info$(0,0))
Knowing from info$(0, 0) how many files we have (call it n), we know that our subdirectory information starts at n + 1, so:
info$(n + 1, 0) - the complete path of a dir (ie. \work\math) info$(n + 1, 1) - the name of the dir (ie. math)
(Directories and subdirectories are often called folders. The names are used interchangeably.)
You can optionally specify a wildcard. This lets you get a list of all *.ini files, for example. This is how you do it:
files DefaultDir$, "*.ini", info$(
This also makes it practical to use to check for file existance. If you want to know if a file c:\config.bak exists, you could try...
files "c:\", "config.bak", info$(
If val(info$(0, 0)) > 0, then the file exists.