Release 10.1A: OpenEdge Development:
Programming Interfaces

> ## 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.
> - M — Member of a Progress r-code library.
> - 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 Progress 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
>     DEFINE VARIABLE search-dir AS CHARACTER.
>     DEFINE VARIABLE file-name AS CHARACTER FORMAT "x(16)" LABEL "File".
>     DEFINE VARIABLE attr-list AS CHARACTER FORMAT "x(4)" LABEL "Attributes".
>     search-dir = OS-GETENV("DLC").
>     INPUT FROM OS-DIR(search-dir).
>     REPEAT:
>        SET file-name ^ attr-list
>              WITH WIDTH 70 USE-TEXT TITLE "Contents of " + search-dir.
>     END.
>     INPUT CLOSE.

> 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 the OpenEdge Development: Progress 4GL 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
>     DEFINE VARIABLE os-file  AS CHARACTER FORMAT "x(60)" LABEL "File".
>     REPEAT:
>       SET os-file WITH FRAME osfile-info.
>       FILE-INFO:FILE-NAME = os-file.
>       DISPLAY FILE-INFO:FULL-PATHNAME FORMAT "x(60)" LABEL "Full Path"
>         FILE-INFO:PATHNAME FORMAT "x(60)" LABEL "Path"
>         FILE-INFO:FILE-TYPE LABEL "Type"
>         WITH FRAME osfile-info SIDE-LABELS TITLE "OS File Info".
>     END.

> For more information, see the `FILE–INFO` System Handle reference entry in the OpenEdge Development: Progress 4GL Reference .

Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095