Windows CMDInteractive Lab
File Managementdir

DIR /B Command: Bare Directory Listing in CMD

Learn how to use DIR /B for clean, script-friendly directory listings in Windows CMD, with practical examples and troubleshooting tips.

Rojan Acharya·
Share

The dir /b command displays a bare directory listing in Windows CMD, showing only file and folder names without headers, sizes, or timestamps. It is the cleanest format for scripts, piping to other commands, or exporting file lists.

Whether you are building automation scripts, preparing file inventories, or quickly listing file names for copy or delete operations, dir /b provides a minimal, predictable output that is easy to parse.

This guide covers syntax, examples, use cases, troubleshooting, related commands, FAQs, and a quick reference card. By the end, you will confidently use dir /b for script-friendly directory listings.

What Is DIR /B?

DIR /B uses bare format in Windows Command Prompt. It outputs only file and directory names, one per line, without the usual heading, summary, size, or date columns. This format is ideal when you need clean input for another command or for saving to a text file.

The command works in all modern Windows versions and is safe to use in production because it is read-only.

Syntax

DIR /B [drive:][path][filename]

Parameters and Options

ParameterDescriptionExample
/BBare formatDIR /B
/SRecursive listingDIR /B /S
/AAttribute filterDIR /B /A:D
pathTarget pathDIR /B C:\Logs

Parameters Explained

/B (Bare Format)

Outputs only names, which makes it ideal for scripting and piping. Example:

DIR /B

/S (Recursive)

Lists files in the target directory and all subdirectories:

DIR /B /S

/A (Attributes)

Filter for directories, hidden files, or other attributes:

DIR /B /A:D
DIR /B /A:H

Examples (HowTo)

1. List names in the current directory

Scenario: You want only filenames for quick copying.

DIR /B

Expected output:

notes.txt
report.docx
logs

Explanation: Only names are shown. Directories are listed without <DIR> markers.

2. List files in a specific folder

Scenario: You need a clean list of a target path.

DIR /B C:\Projects

Explanation: Outputs names from the specified path without changing directories.

3. Recursive bare listing

Scenario: You want all files under a folder for audit.

DIR /B /S C:\Logs

Explanation: Outputs full paths for all files under C:\Logs.

4. List only directories

Scenario: You want a folder-only inventory.

DIR /B /A:D C:\Projects

Explanation: Filters output to directories only.

5. List only hidden items

Scenario: You suspect hidden files in a directory.

DIR /B /A:H C:\Data

Explanation: Shows only items with the hidden attribute.

6. Export a bare listing to a file

Scenario: You need a text file inventory for documentation.

DIR /B /S C:\Projects > C:\Reports\project-files.txt

Explanation: Saves a clean list of files and folders to a file.

Common Use Cases

  1. Script input lists – Feed clean filenames into batch scripts or PowerShell.

  2. File inventories – Export file lists for audits or documentation.

  3. Pipeline filtering – Pipe output to find or findstr for search.

  4. Backup verification – Compare file lists across folders.

  5. Deployment prep – Create lists of files to copy or sync.

  6. Cleanup planning – List files before deletion operations.

  7. Build artifacts – Capture output file names from build directories.

  8. CSV generation – Prepare raw lists for spreadsheet import.

  9. Hidden file audits – Use /A:H to reveal hidden names.

  10. Directory structure capture – Use /A:D for folder-only maps.

Tips and Best Practices

  1. Combine with /S only when needed – Recursive listings can be large.

  2. Use quotes around paths – Avoid errors when paths contain spaces.

  3. Pipe output for filteringDIR /B | FINDSTR ".log" is quick and clean.

  4. Export to a file for analysis – Text files are easier to review.

  5. Check current directory – Use CD before running scripts.

  6. Use /A:D for folder-only lists – Helpful for migration planning.

  7. Validate with DIR without /B – Use full output if you need sizes and dates.

  8. Avoid wildcard confusion – Test wildcard patterns before scripting.

  9. Combine with SORT – Use DIR /B | SORT for alphabetical lists.

  10. Keep output stable – Bare format is consistent across Windows versions.

Troubleshooting Common Issues

Output is empty

Problem: No results appear.

Cause: The directory is empty or you filtered out items.

Solution: Run DIR without /B or remove filters to confirm contents.

Prevention: Confirm path and filters before running scripts.

Paths with spaces fail

Problem: The command errors on paths with spaces.

Cause: Missing quotes around the path.

Solution: Use quotes:

DIR /B "C:\Program Files"

Prevention: Always quote paths with spaces.

Recursive output is too large

Problem: DIR /B /S generates huge output.

Cause: Large directory trees.

Solution: Narrow the path or filter by extension.

Prevention: Use more specific paths and wildcard filters.

Only directories show

Problem: You expected files but only directories appear.

Cause: You used /A:D.

Solution: Remove /A:D or use /A:-D for files only.

Prevention: Double-check attribute filters in scripts.

Related Commands

dir

Full directory listing with sizes, timestamps, and attributes.

sort

Sorts the output alphabetically or by custom rules.

findstr

Filters output by pattern for quick searches.

forfiles

Advanced file selection for automation based on date or size.

tree

Shows directory structure visually for documentation.

Frequently Asked Questions

What does DIR /B do?

It outputs only filenames and folder names without headers, sizes, or timestamps.

Does DIR /B include folders?

Yes. It lists both files and directories unless you filter with /A.

How do I list only files?

Use DIR /B /A:-D to exclude directories.

How do I list only folders?

Use DIR /B /A:D to show directories only.

Can I use DIR /B in PowerShell?

Yes, but PowerShell also has Get-ChildItem for object output.

Why is output different from DIR without /B?

Bare format removes all metadata, leaving only names for scripting.

Can I combine /B with /S?

Yes, DIR /B /S outputs full paths for all files and folders.

How do I export the list?

Redirect output to a file: DIR /B > list.txt.

Quick Reference Card

CommandPurposeExample
DIR /BBare listingDIR /B
DIR /B C:\PathBare listing of a pathDIR /B C:\Logs
DIR /B /SRecursive bare listingDIR /B /S C:\Logs
DIR /B /A:DFolders onlyDIR /B /A:D C:\Projects
DIR /B /A:-DFiles onlyDIR /B /A:-D C:\Projects

CTA: Practice and Explore

Practice directory commands in the Windows Command Simulator and browse the Commands Reference for related file tools like dir, findstr, and sort. Learn more about this project on the About page.

Summary

DIR /B is the simplest way to generate clean, script-friendly directory listings in Windows CMD. It outputs only names, making it ideal for automation, exports, and pipelines. Combine it with /S for recursive lists and /A for filtering when you need more control.

Use bare format whenever you need consistent output for scripts or documentation. For full details like size and dates, fall back to standard DIR, but keep DIR /B as your default for clean file name lists.