When you’re working in Windows Command Prompt, one of the first things you’ll probably type is:
dir
And boom — a list of files and folders appears. It’s simple. It’s fast. It’s the CLI version of File Explorer. But did you know dir
has a bunch of powerful switches that can filter, sort, and format that list to your exact needs?
Let’s go beyond the basics and explore what dir
can really do.
What Is dir
?
The dir
command is used to list files and folders in the current directory (or a specified one). It’s short for “directory”, and it’s been a staple of Windows (and DOS) since forever.
Basic Syntax
dir [path] [options]
Examples:
dir
dir C:\Windows
dir *.txt
Common Switches and What They Do
Here’s a breakdown of the most useful dir
switches (there are quite a few!):
✅ /P
– Pause after each screenful
dir /P
Useful when you’re in a folder with tons of files and don’t want everything to scroll past at warp speed.
✅ /W
– Wide format
dir /W
Displays filenames in columns. Great for a quick overview without details like size and dates.
✅ /B
– Bare format (just filenames)
dir /B
Perfect for scripting. No headers, sizes, or dates — just a clean list.
dir *.txt /B
Example output:
notes.txt
todo.txt
summary.txt
✅ /S
– Include all subdirectories
dir /S
Lists everything under the current directory — including files in all subfolders. Combine with /B
for full paths only:
dir /S /B *.log
✅ /A
– Show files with specific attributes
dir /A:H
Lists hidden files. Other options include:
H
= HiddenS
= SystemD
= DirectoriesR
= Read-onlyA
= Archive
You can combine them:
dir /A:HS
✅ /O
– Sort output
dir /O:N
Sorts by name. Other sort options include:
N
= NameS
= SizeD
= DateE
= ExtensionG
= Group directories first
📦 Example: sort files by size (largest first)
dir /O:-S
✅ /T
– Choose which timestamp to show
dir /T:C
Use with /T:
to display:
C
= Creation timeA
= Last AccessedW
= Last Written (default)
💡 Combined Example
Let’s say you want a list of all .log
files, including subfolders, sorted by size, with full paths and no extra info.
dir *.log /S /B /O:-S
That one-liner is perfect for log cleanup scripts or report generators.
Bonus: Find Junctions and Symlinks
Want to spot symbolic links or junctions?
dir /AL
This shows reparse points — a fancy name for things like symbolic links.
📜 Cheat Sheet Table
Command | What It Does |
---|---|
dir | List contents of current folder |
dir /W | Wide view (filenames only) |
dir /P | Pause after screenful of output |
dir /S | Recursively list all files |
dir /B | Bare format (filenames only) |
dir /A:H | Show hidden files |
dir /O:N | Sort by name |
dir /O:-S | Sort by size (largest first) |
dir /AL | Show symlinks and junctions |
Final Thoughts
The dir
command may seem basic, but with the right switches, it becomes a powerful tool for file audits, scripting, or just finding that lost .ini
file buried 30 folders deep.
So next time you’re inside cmd.exe
, ditch the mouse and let dir
do the digging.
Want to take it further? In an upcoming post, we’ll compare dir
to PowerShell’s Get-ChildItem
— and show how to upgrade from basic output to full-blown file automation.