Windows Tree Command: /F, /A and PowerShell Options

November 11, 2026 · 9 min read

Windows Tree Command: Show Folder Trees in CMD and PowerShell

The Windows tree command draws the folder structure of a drive or path right in Command Prompt or PowerShell. Type tree to list folders, add /F to include files, and add /A for plain ASCII lines. It can't limit depth or skip folders, so this guide also covers the workarounds.

Is There a Tree Command in Windows?

Yes. tree ships with every current version of Windows as tree.com, and it goes back to MS-DOS. Microsoft documents it in the Windows Commands reference for tree, with this syntax.

tree [<drive>:][<path>] [/f] [/a]

Run it without a path and it starts at the current directory. By default it prints folders only, with no files, and it walks every level below the starting point. Windows accepts the switches in either case, so /f and /F do the same thing. You'll find the same tree command in Windows 10, Windows 11 and Windows Server.

The output opens with a short header that names the volume and its serial number. Below that comes the root (shown as C:. when you start in the current folder), then one line per subfolder, connected with box-drawing lines.

How Do You Run Tree in CMD?

Open Command Prompt first. Press Win+R to open the Run dialog, type cmd and press Enter. That's what people mean by Windows R and tree: Run opens a console, then you type the command.

Next, move into the folder you care about and run tree:

cd C:\Users\you\Projects\my-app
tree

You can also skip the cd and pass the path directly, as in tree C:\Users\you\Projects\my-app. A faster route: open the folder in File Explorer, type cmd in the address bar and press Enter. Command Prompt opens already pointed at that folder.

Here's the default output for a small project. Your header lines will differ, since they come from your own drive.

Folder PATH listing for volume OS
Volume serial number is 0000006A 1A2B:3C4D
C:.
├───docs
├───src
│   ├───components
│   └───utils
└───tests

Each ├─── marks a folder with more siblings below it, └─── marks the last folder at that level, and │ carries the line down to deeper entries. For a big folder, pipe the output through more to page it one screen at a time: tree /f | more.

tree /F and tree /A: The Only Switches You Get

The cmd tree command has exactly three switches, and one of them only prints help. That's the whole list, whatever other pages claim.

SwitchWhat it does
/FLists the files inside each folder, not just the folders
/ADraws lines with plain text characters instead of box-drawing glyphs
/?Prints the built-in help

Combine them freely. Here's tree /F /A on the same project.

C:.
|   package.json
|   README.md
|
+---docs
|       guide.md
|
+---src
|   |   index.js
|   |
|   +---components
|   |       Button.js
|   |
|   \---utils
|           format.js
|
\---tests
        app.test.js

With /A, +--- replaces ├───, \--- replaces └───, and a plain | replaces │. Files sit under their folder, indented, with a spacer line after each group.

Some sites list switches like /L, /D, /Q or /T. Those don't exist in tree.com, and it rejects them with an error instead of running. The Unix tree program on Linux (and on macOS via Homebrew) has its own flags, such as -L and -I, and none of them work here either. If you want bare paths with no lines at all, dir /s /b in Command Prompt prints the full path of every file and folder instead.

Saving Tree Output to a Text File Without Garbled Lines

Redirect the output with > to save it. The file lands in whatever folder you're in unless you give a full path:

tree /F /A > tree.txt
tree /F /A > C:\Users\you\Desktop\my-app-tree.txt

Why /A? In Command Prompt, the box-drawing glyphs come out in the console's legacy code page. Depending on that code page and the editor you open the file in, the lines can turn into junk characters. ASCII output looks identical everywhere, so we prefer /A for anything you'll paste into a document, an issue or a chat.

To skip the file entirely, send the output straight to the clipboard with clip:

tree /F /A | clip

It's the quickest way to drop a folder listing into a bug report.

If you redirect from PowerShell instead, the encoding changes. Per Microsoft's about_Character_Encoding page for Windows PowerShell 5.1, > creates UTF-16LE files there, while PowerShell 7 writes UTF-8 without a BOM. Some tools treat a UTF-16 file as binary, so use Out-File -Encoding utf8 in 5.1 (it adds a BOM) if that bites you.

Using the Tree Command in PowerShell

The PowerShell tree command is simply the same tree.com. PowerShell has no built-in cmdlet or alias named tree, so typing it runs the Windows program, and /F and /A behave exactly as they do in cmd. Run Get-Command tree if you want to see which file it resolves to.

PowerShell's native option is Get-ChildItem, which lists paths instead of drawing lines:

Get-ChildItem -Directory -Recurse -Name

That prints one relative path per folder, such as src\components. Drop -Directory to include files. You lose the drawn tree but gain filtering, sorting and depth control, none of which tree.com offers.

Limiting Depth and Skipping node_modules on Windows

This is the real limitation of tree.com: it has no depth limit and no way to exclude a folder. Run it on a JavaScript project and node_modules alone can scroll for thousands of lines. The Unix version has flags for both, covered in our Linux directory tree guide.

For depth, use Get-ChildItem with -Depth, which Microsoft added in PowerShell 5.0. This prints the full path of every folder up to two levels below the current one.

Get-ChildItem -Directory -Depth 1 | ForEach-Object FullName

-Depth 0 returns only the immediate children, and each extra number adds one level. For exclusions, filter the paths after the fact:

Get-ChildItem -Recurse -Name | Where-Object { $_ -notmatch '(^|\\)(node_modules|\.git)(\\|$)' }

PowerShell still walks into node_modules before the filter drops those lines, so this can be slow on a big project. The pattern only drops paths where node_modules or .git is a whole folder name, so .gitignore and .github stay. It also gives you a flat list, not a drawn tree.

When you want a drawn tree without the clutter, use our directory tree generator. Pick or drop a folder and it reads the file paths in your browser, never uploading them, and skips node_modules, .git and build folders. It outputs box-drawing, ASCII, a Markdown list or tree-style text.

Pasting a Windows Tree Command Listing into a README

Folder trees often end up in README files. Wrap the output in a fenced code block tagged text so the spacing and line characters survive rendering. Our guide to Markdown code blocks covers fences in detail.

Here's a short README section built from the default tree output. The demo uses a tilde fence, which works the same as backticks:

my-app

Folder layout

C:.
├───docs
├───src
│   ├───components
│   └───utils
└───tests

Generated with tree in Command Prompt.

21 words140 characters11 lines
Markdown

Without the fence, Markdown collapses the indentation and the tree falls apart. For the rest of the file, see our README Markdown guide. To open the finished .md on your PC, the Windows Markdown viewer guide lists your options.

When tree Shows No Subfolders or Runs for Minutes

A few situations confuse people the first time:

  • Only a header and a message appear. The folder has no subfolders. Add /F to see its files.
  • It runs for minutes. tree C:\ walks the entire drive. Press Ctrl+C to stop it, then point it at a smaller folder.
  • 'tree' is not recognized. In Command Prompt this usually means System32 is missing from your PATH. Some non-Windows shells, such as Git Bash, may not provide tree at all, so open cmd or PowerShell instead.
  • The output looks stale. tree prints a one-time snapshot. Run it again after you add or move folders.

The Windows tree command does one job well: it draws folders and, with /F, files, using box lines or plain ASCII with /A. Pipe it to clip or save it with >, and switch to Get-ChildItem when you need depth control. When node_modules gets in the way, the directory tree generator handles exclusions, and the editor previews the README you paste it into.