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.5
Syntax
 FUNCTION Directory(
	cFileSpec AS STRING,
	 uAttributes AS USUAL
) AS ARRAY

Parameters

cFileSpec
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
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:
CharacterConstant Description
DFA_DIRECTORY Directory
HFC_HIDDEN Hidden
SFC_SYSTEM System
VFA_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):
ConstantDescription
F_ATTRFile attributes (as a string)
F_DATEDate of last update (as a date)
F_NAMEName of file (as a string)
F_SIZESize of file (as a numeric)
F_TIMETime 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.
Remarks
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>.
Examples
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():
X#
1aDirectory := Directory("*.*", "D")
2AEval(aDirectory, {|aFile| QOut(aFile[F_NAME])})
This example obtains an array of information about all files in the current directory:
X#
1aDirectory := Directory("*.*")
This example displays the name, size, date, time, and attribute of each file that matches the file specification *.PRG:
X#
 1Function Start()
 2    LOCAL aDir AS ARRAY
 3    LOCAL i AS DWORD
 4    LOCAL wLen AS DWORD
 5    aDir := Directory("*.prg")
 6    wLen := ALen(aDir)
 7    FOR i := 1 UPTO wLen
 8        ? aDir[i][F_NAME], aDir[i][F_SIZE],;
 9          aDir[i][F_DATE], aDir[i][F_TIME],;
10          aDir[i][F_ATTR]
11    NEXT
12    // Instead of the above FOR loop, you could  
13    // use the AEval() array iterator function as
14    // follows:
15    AEval(aDir, {|aSub| QOut(aSub[F_NAME],;
16        aSub[F_SIZE], aSub[F_DATE], aSub[F_TIME],;
17        aSub[F_ATTR])})
18    RETURN TRUE
See Also