Progress
Programming
Handbook


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 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:

p-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 p-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 Progress Language 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 p-osfile.p procedure prompts for the pathname of a file and then uses the FILE–INFO handle to get information on that file:

p-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 Progress Language Reference .


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