dir

Definition: object x = dir(sequence st)
Description: Return directory information for the file or directory named by st. If there is no file or directory with this name then -1 is returned. On Windows and DOS st can contain * and ? wildcards to select multiple files.

This information is similar to what you would get from the DOS DIR command. A sequence is returned where each element is a sequence that describes one file or subdirectory.

If st names a directory you may have entries for "." and "..", just as with the DOS DIR command. If st names a file then x will have just one entry, i.e. length(x) will be 1. If st contains wildcards you may have multiple entries.

Each entry contains the name, attributes and file size as well as the year, month, day, hour, minute and second of the last modification. You can refer to the elements of an entry with the following constants (automatically defined in psym.e/syminit):
    global constant D_NAME = 1,
              D_ATTRIBUTES = 2,
                    D_SIZE = 3,
                    D_YEAR = 4,
                   D_MONTH = 5,
                     D_DAY = 6,
                    D_HOUR = 7,
                  D_MINUTE = 8,
                  D_SECOND = 9
The attributes element is a string containing characters chosen from:
    'd' -- directory
    'r' -- read only file
    'h' -- hidden file
    's' -- system file
    'v' -- volume-id entry
    'a' -- archive file
 
A normal file without special attributes would just have an empty string, "", in this field.
Comments: The top level directory, e.g. c:\ does not have "." or ".." entries.

This function is often used just to test if a file or directory exists.

Under Windows, st can have a long file or directory name anywhere in the path.

Under Linux, the only attribute currently available is 'd'.

On Windows, the file name returned in D_NAME will be a long file name.
Example:
d = dir(current_dir())
-- d might have:
  {
    {".",    "d",     0  2012, 1, 18,  9, 30, 02},
    {"..",   "d",     0  2012, 1, 18,  9, 20, 14},
    {"fred", "ra", 2350, 2012, 1, 22, 17, 22, 40},
    {"sub",  "d" ,    0, 2013, 9, 20,  8, 50, 12}
  }
d[3][D_NAME] would be "fred"
Example Programs: bin\search.ex , bin\install.ex
See Also: wildcard_file, current_dir, open