Procedure DirectoryGetFiles(directory, filter, filenames, recursive, attributeFilter)


The procedure DirectoryGetFiles creates a list of filenames present in a directory.

        directory,      ! (input) scalar string expression
        filter,         ! (input) scalar string expression
        filenames,      ! (output) a one-dimensional string parameter
        recursive,      ! (optional) default 0
        attributeFilter ! (optional) default: empty set



A scalar string expression representing the directory you want to search. The empty string is interpreted as the current directory.


The pattern file names should match. The empty string is interpreted as all files.


A one-dimensional string parameter indexed over a subset of the predeclared set Integers. This parameter will be filled with the names of the files matching the pattern as specified in the first argument.


An optional scalar expression. When zero the procedure DirectoryGetFiles doesn’t work recursively; it scans only the directory specified, not its subdirectories. When non-zero, these subdirectories will also be searched.


files that have one of the specified attributes will not be included in the result. This argument is a subset of AllFileAttributes.

Return Value

The procedure returns the number of files found on success, which may be 0. If it fails, then it returns -1, and the pre-defined identifier CurrentErrorMessage will contain a proper error message.


Using the declarations

Set FileNumbers {
    SubsetOf     :  Integers;
    Index        :  fn;
StringParameter FileNames {
    IndexDomain  :  (fn);

the statements

DirectoryGetFiles("log", "*.err", Filenames);
display Filenames ;

will result in

FileNames := data { 1 : "aimms.err" } ;

to be printed in the listing file.


  • The directory argument can specify either a relative or an absolute folder path.

  • Devices, hidden files, system files, hidden subdirectories and system subdirectories are not searched. On Linux systems, files and subdirectories that start with a ‘.’ are considered hidden files and are not returned in the result.

See also