ADir()
This function creates an array containing information about files in a specified directory. Read it as "Array from directory" and it makes perfect sense.
Usage |
nCount = ADIR( ArrayName [, cFileSpec [, cAttributes [, nFlag | cCreatorType ] ] ] ) |
Parameter |
Value |
Meaning |
ArrayName |
Array Name |
The array into which directory information is dumped. It's created or resized if necessary. |
cFileSpec |
Character |
Only files matching cFileSpec are included. Wildcards * and ? can be used. cFileSpec can include a drive and directory as well. |
Empty |
When used with a combination of D, H and S attributes, limits results to files matching specified attributes. |
|
Omitted |
Include all files from current drive and directory. |
|
cAttributes (string may contain none, any or all of these four) |
Omitted |
Include only file names, excluding directories and hidden and system files. |
D |
Include information on sub-directories of the specified directory. |
|
H |
Include information on hidden files. |
|
S |
Include information on system files. |
|
V |
Include only the volume information for the specified drive. You don't need to specify the root directory for this to work. Other attributes are ignored if "V" is included. |
|
nFlag (VFP 7 and later) |
0 or omitted |
Put file names into the array in uppercase. |
1 |
Put file names into the array in their original case. |
|
2 |
Put file names into the array using the DOS 8.3 convention. |
|
cCreatorType |
Character |
Mac file creator type—ignored in Windows. |
nCount |
Numeric |
The number of rows in the resulting array; that is, the number of directory entries (files, directories and volume names) for which information was collected. |
0 |
No matching files were found. |
In VFP 5 and earlier, you could get a list of sub-directories for a specified directory by passing the path and a single asterisk for the file name, like this: ADIR(aSubDirs, cPath + "*", "D") This approach doesn't work in VFP 6 and later—that call results in a list containing both files and directories. In those versions, you have to change to the directory of interest and then pass the empty string for the path, like this: CD (cPath) ADIR(aSubDirs, "", "D") Of course, in that case, you have to remember to save the old directory and change back to it afterward. |
Column |
Meaning |
1 |
File name—character. |
2 |
File size in bytes—numeric. |
3 |
Date file was last written—date. |
4 |
Time file was last written—character. |
5 |
File Attributes—a single five-character string. Each
position represents one attribute. If the file has that
attribute, the corresponding letter is there; if not, a
period is found in that location. The attributes are: For example, "R...." means a read-only file, while ".A.H." means a hidden file needing to be archived. |
In VFP 7, IntelliSense pops up a list of choices when you reach the attribute parameter. That's cool. What's not is that the list is wrong. It includes "Archive" and omits "Volume." Choosing "Archive" generates a spurious cAttributes value of "A." It turns out that you can pass pretty much anything for cAttributes without error, so it may be a while before you catch on that you're seeing all files, not just those in need of backup. |
Example |
? ADIR(aFiles) && Creates an array of all files in && current directory. ? ADIR(aDirect, "", "D") && Creates an array of all && subdirectories of current directory. ? ADIR(aDBFs, "*.DBF", 1) && Fills array with list of tables && in their original case. ? ADIR(aDBFs, "DATA\*.DBF", 2)&& Fills array with list of tables && in DATA directory in DOS 8.3 format. |
See Also |
AFields(), Array Manipulation, Dir, Directory(), FDate(), FTime(), Sys(2000) |