Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ dir(CMD) — OpenDesktop 3.0.0

Media Vault

Software Library

Restoration Projects

Artifacts Sought


 dir(CMD)                        19 June 1992                        dir(CMD)


 Name

    dir - display a list of a directory's files and subdirectories

 Syntax


    dir [drive:][path][filename] [/p] [/w] [/a[[:]attributes]]
    [/o[[:]sortorder]] [/s] [/b] [/l]


 Description

    When you use dir without parameters or switches, it displays the disk's
    volume label and serial number; one directory or filename per line,
    including the filename extension, the file size in bytes, and the date
    and time the file was last modified; and the total number of files
    listed, their cumulative size, and the free space (in bytes) remaining on
    the disk.

 Parameters


    [drive:][path]
          Specifies the drive and directory for which you want to see a list-
          ing.

    [filename]
          Specifies a particular file or group of files for which you want to
          see a listing.


 Switches


    /p    Displays one screen of the listing at a time.  To see the next
          screen, press any key.

    /w    Displays the listing in wide format, with as many as five filenames
          or directory names on each line.

    /a[[:] attributes]
          Displays only the names of those directories and files with the
          attributes you specify.  If you omit this switch, dir displays the
          names of all files except hidden and system files.  If you use this
          switch without specifying attributes, dir displays the names of all
          files, including hidden and system files.  The following list
          describes each of the values you can use for attributes.  The colon
          (:) is optional.  Use any combination of these values, and do not
          separate the values with spaces.

             h   Hidden files

             -h  Files that are not hidden

             s   System files

             -s  Files other than system files

             d   Directories

             -d  Files only (not directories)

             a   Files ready for archiving (backup)

             -a  Files that have not changed since the last backup

             r   Read-only files

             -r  Files that are not read-only

    /o[[:] sortorder]
          Controls the order in which dir sorts and displays directory names
          and filenames.  If you omit this switch, dir displays the names in
          the order in which they occur in the directory.  If you use this
          switch without specifying sortorder, dir displays the names of the
          directories, sorted in alphabetic order, and then displays the
          names of files, sorted in alphabetic order.  The colon (:) is
          optional.  The following list describes each of the values you can
          use for sortorder.  Use any combination of the values, and do not
          separate these values with spaces.

             n   In alphabetic order by name

             -n  In reverse alphabetic order by name (Z through A)

             e   In alphabetic order by extension

             -e  In reverse alphabetic order by extension (Z through A)

             d   By date and time, earliest first

             -d  By date and time, latest first

             s   By size, smallest first

             -s  By size, largest first

             g   With directories grouped before files

             -g  With directories grouped after files

    /s    Lists every occurrence, in the specified directory and all sub-
          directories, of the specified filename.

    /b    Lists each directory name or filename, one per line (including the
          filename extension).  This switch displays no heading information
          and no summary.  The /b switch overrides the /w switch.

    /l    Displays unsorted directory names and filenames in lowercase.  This
          switch does not convert extended characters to lowercase.


 Notes


    Using wildcards with dir

    You can use wildcards (? and *) to display a listing of a subset of files
    and subdirectories.  For an example illustrating the use of a wildcard,
    see the following ``Examples'' section.

    Specifying file display attributes

    If you specify the /a switch with more than one value in attributes, dir
    displays the names of only those files with all the specified attributes.
    For example, if you specify the /a switch with the r and -h values for
    attributes by using either /a:r-h or /ar-h, dir displays only the names
    of read-only files that are not hidden.

    Specifying filename sorting

    If you specify more than one sortorder value, dir sorts the filenames by
    the first criterion first, then by the second criterion, and so on.  For
    example, if you specify the /o switch with the e and -s values for sor-
    torder by using either /o:e-s or /oe-s, dir sorts the names of direc-
    tories and files by extension, with the largest first, and displays the
    final result.  The alphabetic sorting by extension causes filenames with
    no extensions to appear first, then directory names, then filenames with
    extensions.

    Setting date and time formats

    The date and time formats used by dir depend on the country setting you
    use in your CONFIG.SYS file.  If you do not use the country command, the
    formats are those for the United States.

    Using redirection symbols and pipes

    When you use a redirection symbol (>) to send dir output to a file or a
    pipe (|) to send dir output to another command, use the /a:-d and /b
    switches to list only the filenames.  You can use the filename parameter
    with the /b and /s switches to specify that dir is to search the current
    directory and its subdirectories for all filenames that match filename.
    dir lists only the drive letter, directory name, filename, and filename
    extension, one path per line, for each filename it finds.

    Before using a pipe for redirection, you should set the TEMP environment
    variable in your AUTOEXEC.BAT file.

    Presetting dir parameters and switches

    You can preset dir parameters and switches by including the set command
    with the DIRCMD environment variable in your AUTOEXEC.BAT file.  You can
    use any valid combination of dir parameters and switches with the set
    DIRCMD command, including the location and name of a file.

    For example, to use the DIRCMD environment variable to set the wide dis-
    play format (/w) as the default format, include the following command in
    your AUTOEXEC.BAT file:

       set dircmd=/w


    For a single use of the dir command, you can override a switch set by
    using the DIRCMD environment variable.  To do so, you use the same switch
    on the dir command line, but you must also precede the switch letter with
    a minus sign, as the following example shows:

       dir /-w


    You can change the DIRCMD default settings by typing the set command at
    the command prompt with a new parameter or switch after the equal sign
    (=).  The new default settings are effective for all subsequent dir com-
    mands until you use set DIRCMD again on the command line or until you
    restart MS-DOS.

    To clear all default settings, type the following command:

       set dircmd=


    You can view the current settings of the DIRCMD environment variable by
    typing the following command:

       set


    MS-DOS displays a list of environment variables and their settings.  For
    more information about setting environment variables, see the set(CMD)
    command.

 Examples

    Suppose you want dir to display one directory listing after another,
    until it has displayed the listing for every directory on the disk in the
    current drive.  Suppose also that you want dir to alphabetize each direc-
    tory listing, display it in wide format, and pause after each screen.  To
    specify such a display, be sure the root directory is the current direc-
    tory and then type the following command:

       dir /s/w/o/p

    dir lists the name of the root directory, the names of the subdirectories
    of the root directory, and the names of the files in the root directory
    (including extensions).  Then dir lists the subdirectory names and
    filenames in each subdirectory in the directory tree.

    To alter the preceding example so that dir displays the filenames and
    extensions but omits the directory names, type the following command:

       dir /s/w/o/p/a:-d

    To print a directory listing, type the redirection symbol and prn after
    any form of the dir command, as the following example shows:

       dir > prn


    When you specify prn on the dir command line, the directory listing is
    sent to the printer attached to the LPT1 port.  If your printer is
    attached to a different port, you must replace prn with the name of the
    correct port.

    You can also redirect output of the dir command to a file by replacing
    prn with a filename.  A path is also accepted on the command line.  For
    example, to direct dir output to the file DIR.DOC in the RECORDS direc-
    tory, type the following command:

       dir > \records\dir.doc


    If DIR.DOC does not exist, MS-DOS creates it, unless the directory
    RECORDS also does not exist.  In that case, MS-DOS displays the following
    message:

       File creation error


    To display a list of all the filenames with the .TXT extension in all
    directories on drive C, type the following command:

       dir c:\*.txt /w/o/s/p


    dir displays, in wide format, an alphabetized list of the matching
    filenames in each directory and pauses each time the screen fills, until
    you press a key to continue.

 Related command

    For information about displaying the directory structure of a path or
    disk, see the tree(CMD) command.


Typewritten Software • bear@typewritten.org • Edmonds, WA 98026