Directory Function | |
Create an array of directory and file information.
Namespace:
XSharp.RT
Assembly:
XSharp.RT (in XSharp.RT.dll) Version: 2.21
Syntax FUNCTION Directory(
cFileSpec AS STRING,
uAttributes AS USUAL
) AS ARRAY
public static Array Directory(
string cFileSpec,
[DefaultParameterValueAttribute(0, 1)] Usual uAttributes
)
Request Example
View SourceParameters
- 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:
Character | Constant Description |
---|
D | FA_DIRECTORY Directory |
H | FC_HIDDEN Hidden |
S | FC_SYSTEM System |
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):
Compared to earlier Xbase versions the return value of Directory() has changed:
each subarray returned from Directory() now contains some extra values, such as creation date and
last access date. The normal F_DATE and F_TIME elements represent the last written date and time.
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) |
F_WRITE_DATE | Time of last file write date (as a date) |
F_WRITE_TIME | Time of last file write time (as a string) |
F_CREATION_DATE | Time of file creation date (as a date) |
F_CREATION_TIME | Time of file creation time (as a string) |
F_ACCESS_DATE | Time of last access date (as a date) |
F_ACCESS_TIME | Time of last access time (as a string) |
F_EA_SIZE | .Net File attributes for the file |
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():
1aDirectory := Directory("*.*", "D")
2AEval(aDirectory, {|aFile| QOut(aFile[F_NAME])})
This example obtains an array of information about all files in the current directory:
1aDirectory := Directory("*.*")
This example displays the name, size, date, time, and attribute of each file that matches the file specification *.PRG:
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
13
14
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