Click or drag to resize

Directory Function

Create an array of directory and file information.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.2a
 FUNCTION Directory(
	cFileSpec AS STRING,
	uAttributes AS USUAL := NIL
View Source


Type: String
The file specification for the search.  Besides a file name, this specification can include an optional drive, directory, and extension.  The file name and extension can include the standard wildcard characters (* and ?).  If you do not specify a drive and directory, the Windows defaults are used.
uAttributes (Optional)
Type: Usual
Specifies inclusion of files with special attributes in the returned information.  <uAttributes> can be a string or a numeric.  When specified as a string it can contain one or more of the characters listed in the table below.  When specified as a numeric it can contain one or more of the constants listed in the following table:
Character Constant Description
V FA_VOLUME Volume label
To specify more than one constant, you can either add attributes together using the + operator, or use the _Or() operator, as in this example: _Or(FC_SYSTEM, FC_HIDDEN).  To specify more than one string, simply concatenate them, as in "SH."
<uAttributes> specifies a criterion to satisfy in addition to any "visible" files that match the <cFileSpec>.  Visible files do not include directories, volumes, or hidden or system files — all other files are visible, regardless of the status of their read or archive attributes.  To include only visible files, omit this argument.
Note:To specify volume labels only, to the exclusion of all other files, specify FA_VOLUME or "V" as the sole <uAttributes> argument.

Return Value

Type: Array
An array of subarrays, with each subarray containing information about each file matching <cFileSpec>.  The subarray elements are referenced as follows (see example below): Constant Description F_ATTR File attributes (as a string) F_DATE Date of last update (as a date) F_NAME Name of file (as a string) F_SIZE Size of file (as a numeric) F_TIME Time of last update (as a string) If no files are found matching <cFileSpec> or if <cFileSpec> is an illegal path or file specification, Directory() returns an empty array.
Directory() returns information about files in the current or specified directory.  You can use it to perform actions on groups of files.  In combination with AEval(), you can define a block that can be applied to all files matching the specified <cFileSpec>.
This example obtains an array of information about all files and directories in the current directory then lists the names of the files using AEval() and QOut():
aDirectory := Directory("*.*", "D")
AEval(aDirectory, {|aFile| QOut(aFile[F_NAME])})
This example obtains an array of information about all files in the current directory:
aDirectory := Directory("*.*")
This example displays the name, size, date, time, and attribute of each file that matches the file specification *.PRG:
Function Start()
        LOCAL aDir AS ARRAY
        LOCAL i AS DWORD
        LOCAL wLen AS DWORD
        aDir := Directory("*.prg")
        wLen := ALen(aDir)
        FOR i := 1 UPTO wLen
                ? aDir[i][F_NAME], aDir[i][F_SIZE],;
                  aDir[i][F_DATE], aDir[i][F_TIME],;
        // Instead of the above FOR loop, you could  
        // use the AEval() array iterator function as
        // follows:
        AEval(aDir, {|aSub| QOut(aSub[F_NAME],;
                aSub[F_SIZE], aSub[F_DATE], aSub[F_TIME],;
See Also