For each file or folder listed, the command will, by default, show the date and time the item was last changed, if the item is a folder (labeled with DIR) or file, the size of the file if applicable, and finally the name of the file or folder including the file extension. Outside of the file and folder list, the dir command also displays the current drive letter of the partition, the volume label, volume serial number, total number of files listed, total size of those files in bytes, the number of subfolders listed, and the total bytes remaining free on the drive.

Dir Command Availability

The dir command is available from within the Command Prompt in all Windows operating systems including Windows 11, Windows 10, Windows 8, Windows 7, Windows Vista, and Windows XP. Older versions of Windows include the dir command as well but with a few fewer options than we have listed below. The dir command is also a DOS command, available in all versions of MS-DOS. The dir command can be found in offline Command Prompt versions, like the ones available from Advanced Startup Options and System Recovery Options. The dir command is also included in the Recovery Console in Windows XP.

Dir Command Syntax

dir [drive:][path][filename] [/a[[:]attributes]] [/b] [/c] [/d] [/l] [/n] [/o[[:]sortorder]] [/p] [/q] [/r] [/s] [/t[[:]timefield]] [/w] [/x] [/4] a = archive files d = directories h = hidden files i = not content indexed files l = reparse points r = read-only files s = system files v = integrity files x = no scrub files

  • = Use this as a prefix to any of the above attributes to exclude items with those file attributes from the results. d = sort by date/time (oldest first) e = sort by extension (alphabetical) g = group directory first, followed by files n = sort by name (alphabetical) s = sort by size (smallest first)
  • = Use this as a prefix with any of the above values to reverse the order (-d to sort by newest first, -s for largest first, etc.). a = last access c = created w = last written

Run Without Switches

In this example, the dir command is used alone, without any drive:, path, filename specifications, nor any switches, producing a result like this: As you can see, the dir command was executed from the root directory of C (i.e., C:>). Without specifying where exactly to list the folder and file contents from, the command defaults to displaying this information from where the command was executed.

List Hidden Items

In the above example, we’re requesting that the dir command show results from the drive: and path of c:\users, not from the location we’re running the command from. We’re also specifying, via the /a switch with the h attribute, that we’d like to only see hidden items, resulting in something like this: The small list of directories and the single file you see in the result above doesn’t make up the entirety of the c:\users folder—just the hidden files and folders. To see all files and folders, you would execute dir c:\users /a (removing the h) instead.

Search for File In Any Folder

In this slightly more complex, but much more practical, example for the dir command, we’re requesting that our entire hard drive be searched for CSV files and then the bare minimum results are outputted to a text document. Let’s look at this piece by piece:

c:*.csv tells the dir command to look at all files (*) that end in the CSV (.csv) extension in the root of the c: drive. /s instructs it to go deeper than the root of c: and instead, search for files like this in every folder, as deep as the folders go. /b removes anything but the path and file name, essentially creating a readable “list” of these files. > is a redirection operator, meaning “send to” somewhere. c:\users\tim\desktop\csvfiles.txt is the destination for the > redirector, meaning that results will be written to the csvfiles.txt file instead of in Command Prompt, which will be created at the c:\users\tim\desktop location (i.e., the Desktop you see when you’re logged in).

When you redirect command output to a file, as we did here in this dir command example, Command Prompt doesn’t display anything. However, the exact output you would have seen is instead located inside that text file. Here’s what our csvfiles.txt looked like after the dir command had completed: While you certainly could have skipped the file redirection, and even the “bare format” switch, the results would have been very difficult to work within the Command Prompt window, making it hard to get to what you were after.

The dir command is often used with the del command. After using dir to find the name and location of the file(s) in any particular folder(s), del can be used to delete files directly from the Command Prompt. Similar is the rmdir /s command, and older deltree command, used to delete folders and files. The rmdir command (without the /s option) is useful for deleting empty folders that you find with the dir command. As mentioned above, the dir command is also often used with a redirection operator.