Professional Documents
Culture Documents
com
DIR
Display a list of files and subfolders.
Syntax
DIR [pathname(s)] [display_format] [file_attributes] [sorted] [time] [options]
Key
[pathname] The drive, folder, and/or files to display,
this can include wildcards:
* Match any characters
? Match any ONE character
[display_format]
/P Pause after each screen of data.
/W Wide List format, sorted horizontally.
/D Wide List format, sorted by vertical column.
[file_attributes] /A[:]attribute
[time] /T: the time field to display & use for sorting
/T:C Creation
/T:A Last Access
/T:W Last Written (default)
[options]
/S include all subfolders.
/R Display alternate data streams.
/B Bare format (no heading, file sizes or summary).
/L use Lowercase.
/Q Display the owner of the file.
https://ss64.com/nt/dir.html 1/3
3/15/2021 DIR - list files and folders - Windows CMD - SS64.com
The switches above can be preset by adding them to an environment variable called DIRCMD.
For example: SET DIRCMD=/O:N /S
Sorting
The default Sort Order, if you don’t specify anything with /O, on an NTFS drive will be in sort-of-alphabetical order or on a FAT USB
thumb drive, then the order will be based on the order in which files were created and deleted and the lengths of their names.
To obtain a bare DIR format (no heading or footer info) but retain all the details, pipe the output of DIR into FIND, this assumes that
your date separator is /
If you want to list the full path without including subfolders, use the FOR command as in this example script.
Errorlevels
If the file(s) were successfully listed %ERRORLEVEL% = 0
If the file was not found or bad parameters given %ERRORLEVEL% = 1
Examples
DIR /a c:\demo\
DIR /b c:\demo\
List only the files (not folders) stored under c:\demo\ recursing into all sub-folders and include any hidden files:
List all the Reparse Points (symbolic links) in the current users profile:
List the contents of c:\demo with the full path of each file (source)
Related
https://ss64.com/nt/dir.html 2/3