Reading the contents of a directory
- Last Updated: January 17, 2024
- 2 minute read
- OpenEdge
- Version 12.8
- Documentation
Reading the contents of a directory
Sometimes, rather than reading the contents of a file,
you want to read a list of the files in a directory. You can use
the OS–DIR option of the INPUT FROM statement
for this purpose.
Each line read from OS–DIR contains three values:
- The simple (base) name of the file.
- The full pathname of the file.
- A string value containing one or more attribute characters.
These characters indicate the type of the file and its status. Every
file has one of the following attribute characters:
- F — Regular file or FIFO pipe
- D — Directory
- S — Special device
- X — Unknown file type
In addition, the attribute string for each file might contain one or more of the following attribute characters:
- H — Hidden file
- L — Symbolic link
- P — Pipe file
The tokens are returned in the standard ABL format that can be
read by the IMPORT or SET statements.
The following example uses the OS–GETENV function to
find the path of the DLC directory. It then
uses the OS–DIR option of INPUT FROM to read
the contents of the directory:
i-osdir.p
|
In i-osdir.p, only the base name of the
file and attribute string are read from OS–DIR.
The caret (^) is used in the SET statement to skip
over the pathname of the file.
For more information on the OS–DIR option, see
the INPUT FROM Statement reference entry
in ABL Reference.
You can find additional information on a single file by using
the FILE–INFO system handle. To use the FILE–INFO handle,
first assign the pathname of an operating system file to the FILE–INFO:FILE–NAME attribute.
You can then read other FILE–INFO attributes. For example,
the i-osfile.p procedure prompts for the pathname of
a file and then uses the FILE–INFO handle to get
information on that file.
i-osfile.p
|
For more information, see the FILE–INFO System Handle
reference entry in ABL Reference.