Displays a list of a directory's files and subdirectories. Used without parameters, dir displays the disk's volume label and serial number, followed by a list of directories and files on the disk, including their names and the date and time each was last modified. For files, dir displays the name extension and the size in bytes. Dir also displays the total number of files and directories listed, their cumulative size, and the free space (in bytes) remaining on the disk.
dir [Drive:][Path][FileName] [...] [/p] [/q] [/w] [/d] [/a[[:]attributes]][/o[[:]SortOrder]] [/t[[:]TimeField]] [/s] [/b] [/l] [/n] [/x] [/c] [/4]
[Drive:][Path] : Specifies the drive and directory for which you want to see a listing.
[FileName] : Specifies a particular file or group of files for which you want to see a listing.
/p : Displays one screen of the listing at a time. To see the next screen, press any key on the keyboard.
/q : Displays file ownership information.
/w : Displays the listing in wide format, with as many as five file names or directory names on each line.
/d : Same as /w but files are sorted by column.
/a [[:] attributes] : Displays only the names of those directories and files with the attributes you specify. If you omit /a, dir displays the names of all files except hidden and system files. If you use /a 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.
/o [[:]SortOrder] : Controls the order in which dir sorts and displays directory names and file names. If you omit /o, dir displays the names in the order in which they occur in the directory. If you use /o 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 white spaces.
/t [[:]TimeField] : Specifies which time field to display or use for sorting. The following list describes each of the values you can use for TimeField.
/s : Lists every occurrence, in the specified directory and all subdirectories, of the specified file name.
/b : Lists each directory name or file name, one per line, including the file name extension. /b does not display heading information or a summary. /b overrides /w.
/l : Displays unsorted directory names and file names in lowercase. /l does not convert extended characters to lowercase.
/n : Displays a long list format with file names on the far right of the screen.
/x : Displays the short names generated for files on NTFS and FAT volumes. The display is the same as the display for /n, but short names are displayed after the long name.
/c : Displays the thousand separator in file sizes.
/4 : Displays four-digit year format.
/? : Displays help at the command prompt.
To display all directories, one after the other, in alphabetical order, in wide format and pausing after each screen, make sure that the root directory is the current directory, and then type:
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 file names in each subdirectory in the tree.
To alter the preceding example so that dir displays the file names and extensions, but omits the directory names, type:
To print a directory listing, type:
dir > prn
When you specify prn, the directory list 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 file name. You can also type a path. For example, to direct dir output to the file Dir.doc in the Records directory, type:
dir > \records\dir.doc
If Dir.doc does not exist, dir creates it, unless the Records directory does not exist. In that case, the following message appears:
File creation error
To display a list of all the file names with the .txt extension in all directories on drive C, type:
dir c:\*.txt /w/o/s/p
Dir displays, in wide format, an alphabetized list of the matching file names in each directory and pauses each time the screen fills up, until you press a key to continue.