Directory Function | |
Create an array of directory and file information.
Namespace:
XSharp.RT
Assembly:
XSharp.RT (in XSharp.RT.dll) Version: 2.19
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:
Constant | Description |
---|
FA_DIRECTORY |
Directory
|
FA_VOLUME |
Vorume
|
FC_HIDDEN |
Hidden
|
FC_NORMAL |
Visible
|
FC_SYSTEM |
System
|
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.
Tip |
---|
If you specify a file specification that includes a drive or directory, the uAttributes argument is ignored.
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.
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