Function Directory() Foundation

Fills an array with information about the files in a specified path.

Directory( [<cDirectory>], [<cAttribute>] ) --> aDirectory
<cDirectory> is a character string specifying the drive, path and file from which file information is read into an array. A file mask can be defined by using "wildcards" (* or ?) as part of the file name. If no <cDirectory> is specified, "*" is used, and all file information in the current path is read.
The argument <cAttribute> is a string which can be used to extend the files placed in the array based on their file attributes. <cAttribute> may specify one or more of the following characters: "D","H","S","V". When "V" is specified only the name of the disk volume (volume) is retrieved and the files are ignored. The meaning of the valid characters for <cAttribute> is as follows:
Directory()-file attributes
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 "". The contents of each array column are given in the following table:

Columns in the Directory() array
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
  1. These constants are only included for compatibility

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 "" 

   LOCAL aDbfFiles := Directory("*.DBF") 
   LOCAL nCount    := Len(aDbfFiles) 
   LOCAL n, nSum 

   nSum := 0 

   FOR n:= 1 TO nCount 
       nSum += aDbfFiles[ n, F_SIZE ] 

   ? nCount, "DBF files occupying", nSum, "Bytes" 
Write file information into a file

// 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 "" 

   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 

   // 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 ]    ) } ) 




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.