Function Directory() Foundation
Fills an array with information about the files in a specified path.
Directory( [<cDirectory>], [<cAttribute>] ) --> aDirectory
Attribute | Meaning | |
---|---|---|
D | Directory | directories are also listed |
H | Hidden | hidden files are also listed |
S | System | system files are also listed |
V | Volume | retrieves name of the disk volume and ignores files |
The return value of Directory() is a two dimensional array containing information about one of the files specified by <cDirectory> in each subarray. The array columns can be identified using symbolic constants defined in the Header file "Directry.ch". The contents of each array column are given in the following table:
Constant | Contents | data type |
---|---|---|
F_NAME | file name | C |
F_SIZE | size of the file | N |
F_WRITE_DATE | date of last update | D |
F_DATE *) | compatibility constant | |
F_WRITE_TIME | time of last update | C |
F_TIME *) | compatibility constant | |
F_ATTR | file attribute | C |
F_EA_SIZE | size of the extended file attributes | N |
F_CREATION_DATE | date of creation | D |
F_CREATION_TIME | time of creation | C |
F_ACCESS_DATE | date of last opening | D |
F_ACCESS_TIME | time of last opening | C |
|
When <cDirectory> contains an invalid path or file specification, or no matching files are found, an empty array ({}) is returned.
The environment function Directory() provides file information about all or a specific type of files in the specified path. Operations can be performed on the selected files using the array returned by Directory(). It should be noted that file names in the HPFS and NTFS file systems have a maximum length of 255 characters and can be mixed case. In the FAT file system, file names have a maximum of 12 characters and are always upper cased.
// In the example, the number of bytes being consumed
// by DBF files in the current directory is determined
#include "Directry.ch"
PROCEDURE Main
LOCAL aDbfFiles := Directory("*.DBF")
LOCAL nCount := Len(aDbfFiles)
LOCAL n, nSum
nSum := 0
FOR n:= 1 TO nCount
nSum += aDbfFiles[ n, F_SIZE ]
NEXT
? nCount, "DBF files occupying", nSum, "Bytes"
RETURN
// In the example all PRG files are read,
// sorted by file name, and all file information
// is listed in an output file using AEval() and
// QOut()
#include "Directry.ch"
PROCEDURE Main
LOCAL aPrgFiles := Directory("*.PRG")
// sort array by file name
ASort( aPrgFiles,,, {|a1,a2| a1[ F_NAME ] < a2[ F_NAME ] } )
// divert print output to file
SET PRINTER TO Prglist.txt
SET PRINTER ON
// output array
AEval( aPrgFiles, ;
{|a| QOut( PadR( a[ F_NAME ], 30 ) , ;
a[ F_SIZE ] , ;
a[ F_WRITE_DATE ] , ;
a[ F_WRITE_TIME ] , ;
a[ F_ATTR ] , ;
a[ F_EA_SIZE ] , ;
a[ F_CREATION_DATE ], ;
a[ F_CREATION_TIME ], ;
a[ F_ACCESS_DATE ] , ;
a[ F_ACCESS_TIME ] ) } )
SET PRINTER TO
SET PRINTER OFF
RETURN
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.