1. Home
  2. DIRECTORY procedure

DIRECTORY procedure

Prints or saves a list of files and/or subdirectories with names matching a specified mask (D.B. Baird).

Options

PRINT = string tokens What to print (filenames, subdirectories); default file
SAVEPATH = string token Whether to include the path in FILENAMES (yes, no); default no
MASKTYPE = string token The type of mask specified by MASK (file, directory); default file

Parameters

MASK = texts Mask identifying the files that are to be included in the each listing, if no directory path is included, the current working directory is searched; default '*.*'
FILENAMES = texts Saves the list of files that match each mask
SUBDIRECTORIES = texts Saves the list of subdirectories that match each mask

Description

DIRECTORY obtains lists of files or subdirectories matching a specified template. The file and subdirectory lists can be saved in the texts supplied by the FILENAMES and SUBDIRECTORIES parameters respectively. The SAVEPATH option controls whether the filenames also include the path.

Printed output is controlled by the PRINT option, with settings:

    filenames to print the list of files, and
    subdirectories to print the subdirectories.

The template is specified in a text with a single value, using the MASK parameter. It uses the standard conventions of the DOS DIR command but, for convenience, you can put / instead of \, as in other Genstat file specifications. So, for example, you can list the files with a suffix .GEN in the folder (or directory) c:\genprog by putting either

DIRECTORY 'c:\\genprog\\*.gen'

or

DIRECTORY 'c:/genprog/*.gen'

(The doubling of each symbol \within the string is required as usual to tell Genstat that it should not be treated as the continuation symbol.) If no directory is specified in the template (e.g. MASK='*.gen'), the current working directory is searched.

If the MASKTYPE option is set to directory then the MASK parameter is interpreted as being a directory, and all the files or subdirectories within this directory are returned. For example the following program prints and saves all the files within the subdirectories of the current working directory

GET [WORKINGDIRECTORY=CDir]

DIRECTORY [PRINT=*;MASKTYPE=directory] CDir; SUBDIRECTORIES=Subs

FOR [INDEX=i] SD=#Subs

    CONCAT [NEWTEXT=SDir] CDir,'/',SD

    DIRECTORY [MASKTYPE=directory] SDir; FILE=Files[i]

ENDFOR

Options: PRINT, SAVEPATH, MASKTYPE.

Parameters: MASK, FILENAMES, SUBDIRECTORIES.

Method

The file list is obtained by a call to SUSPEND with a DIR command.

See also

Directive: SUSPEND.

Procedure: %CD.

Updated on March 8, 2019

Was this article helpful?