Windows CMDInteractive Lab
windows commands

DIR /S Command: Recursive Listing in Windows CMD

Master DIR /S for recursive file listings in Windows CMD, including useful switch combinations, filtering, and troubleshooting large-output scenarios.

Rojan Acharya··Updated Apr 20, 2026
Share

dir /s lists files and folders recursively through all subdirectories under a target path. It is one of the fastest built-in commands for inventory, troubleshooting, and script pre-checks before file operations.

This guide covers syntax, useful switch combinations, practical examples, and ways to manage large output safely.

What Does dir /s Do?

It walks the current or specified directory tree and prints entries from nested folders, not just the top-level directory.

Syntax

dir [path] /s
dir [path] /s /b
dir [path] /s /a[:attributes]
SwitchMeaning
/srecursive listing
/bbare format (path-focused)
/afilter by attributes
/osort output

Parameters / Options

/s

Core recursive traversal behavior.

/b

Cleaner output for script consumption.

/a

Filter hidden/system/other attribute classes.

/o

Sort by name, date, size, and direction.

Examples

1. Recursive listing from current path

dir /s

2. Recursive list specific folder

dir C:\Logs /s

3. Bare recursive output for scripts

dir C:\Logs /s /b

4. Hidden files recursively

dir C:\Data /s /a:h

5. Recursive sorted by size

dir C:\Data /s /o:s

6. Save recursive inventory

dir C:\Data /s /b > C:\Temp\data-inventory.txt

Common Use Cases

  • Inventorying files before migration.
  • Locating hidden files in troubleshooting.
  • Pre-checking deletion targets in maintenance scripts.
  • Producing file-tree evidence for incident tickets.
  • Finding large data footprints in storage triage.

Tips and Best Practices

  • Use /b for automation-friendly output.
  • Redirect large output to files for review.
  • Scope paths narrowly to reduce runtime/noise.
  • Combine with attribute filters to target investigation goals.
  • Run pre-check and post-check inventories for change evidence.

Troubleshooting Common Issues

Output is too large

Use specific paths and filters, then redirect to a file.

Access denied in subfolders

Run elevated if needed or skip protected directories.

Command seems slow

Large trees and network paths can be expensive; narrow scope.

Missing hidden/system entries

Add /a filters such as /a:h or /a:s.

Related Commands

tree

Directory structure visualization.

where

Find executable locations quickly.

forfiles

Conditional recursive file processing.

findstr

Filter textual outputs from command pipelines.

Frequently Asked Questions

Is dir /s recursive?

Yes, it traverses subdirectories.

What is the best script format with dir /s?

Use /b for path-only output.

Can I target hidden files only?

Yes, combine with /a:h.

Does it include folders and files?

Standard output includes both context and entries.

How do I save output?

Redirect with > to a file path.

Why do I get access denied lines?

Protected folders require permissions/elevation.

Is this command destructive?

No, dir is read-only listing.

Can I use it on network shares?

Yes, but performance depends on share size and latency.

Quick Reference Card

CommandPurpose
dir /srecursive listing
dir path /s /bscript-friendly recursive paths
dir path /s /a:hrecursive hidden-file view
dir path /s /o:srecursive sort by size

Summary

dir /s is a reliable recursive listing command for Windows CMD. With the right switch combinations, it becomes a strong diagnostic and automation pre-check tool for support, operations, and migration workflows.