Windows CMDInteractive Lab
File Managementdir

Command Prompt List Directories: Best Commands

Learn how to list directories in Command Prompt using DIR options for folders only, recursive scans, sorting, and export-ready output.

Rojan Acharya··Updated Apr 17, 2026
Share

To list directories in Command Prompt, use the DIR command with directory-only filtering. The most direct command is DIR /A:D, and you can combine it with recursion, sorting, and bare mode for cleaner output.

What Command Lists Directories in CMD?

The base command is:

DIR /A:D

/A:D filters output to folder entries only.

Syntax

DIR [path] /A:D [/S] [/B] [/O:N]

Practical Directory Listing Commands

DIR /A:D
DIR C:\Projects /A:D
DIR /A:D /S
DIR /A:D /B /S
DIR /A:D /O:N

Common Use Cases

  • Build folder inventory before migration.
  • Confirm nested folders created by installers.
  • Audit project structure across repositories.
  • Compare folder structures between environments.

Tips and Best Practices

  • Use /B if output is consumed by scripts.
  • Add /S only when recursion is required.
  • Combine with absolute path for repeatability.

Troubleshooting Common Issues

Output includes files

Ensure /A:D is present and not negated.

Output is too verbose

Use /B to reduce noise.

Missing folders

Try DIR /A if hidden/system directories are involved.

Permission denied

Run elevated CMD for protected paths.

Related Commands

Frequently Asked Questions

How do I list only directories in CMD?

Use DIR /A:D.

How do I list directories recursively?

Use DIR /A:D /S.

How do I export folder list to a file?

Use DIR /A:D /B /S > folders.txt.

Can I sort directories alphabetically?

Yes, use DIR /A:D /O:N.

Does this work on Windows 10 and 11?

Yes.

Can I include hidden directories?

Use DIR /A:DH.

Why does it show short names sometimes?

That happens with short-name display options.

Is there a visual tree view alternative?

Yes, TREE.

Quick Reference Card

CommandPurpose
DIR /A:DFolders only
DIR /A:D /SRecursive folders
DIR /A:D /B /SExport-ready folder list
DIR /A:DHHidden directories
DIR /A:D /O:NSorted by name

CTA

Practice directory-only listing in the simulator and explore all listing options in Commands Reference.

Summary

For listing directories in Command Prompt, start with DIR /A:D. Add /S, /B, and /O:N depending on recursion, script output, and sorting needs.