tree - Display Directory Structure
Table of Contents
Opening folders one by one in File Explorer to check a folder structure takes time.
The tree command displays the whole directory hierarchy in tree form at once.
It is handy for checking a project layout, pasting a structure into documentation, or recording a layout before a backup.
Quick Reference: Copy-Paste tree Commands
| Goal | Command |
|---|---|
| Show folders only | tree |
| Include files | tree /F |
| Avoid garbled line characters (ASCII) | tree /A |
| Include files, ASCII characters | tree /F /A |
| Save the result to a text file | tree /F /A > tree.txt |
| Show a specific folder | tree /F "C:\Users\user\Documents" |
tree has no option to limit the depth or to exclude folders. The formatter below fills both gaps.
Limit Depth and Exclude Folders (Tree Formatter)
Run tree /F /A | clip to copy the tree to the clipboard, then paste it below. Choose how many levels to show and which folder names to drop, and get a tree that is easy to paste into a README or document (├── style, ASCII, or a Markdown list).
Paste the output of tree /F /A to limit the depth, drop folders such as node_modules, and reformat it for a README or document.
Paste the output of tree /F /A above and the formatted tree appears here.
Everything is processed on this page. Nothing you paste is sent anywhere.
It also reads output with line-drawing characters (without /A) and path lists from dir /s /b.
What Is the tree Command
The tree command graphically displays the directory structure under a specified path.
- Check a project folder layout at a glance
- Paste a directory structure into a README or design document
- Record the folder layout before a backup
- Quickly check whether subfolders exist
Basic Usage
The syntax of the tree command is as follows.
tree [drive:][path] [/F] [/A]
Without options, it displays the folder structure under the current directory.
Specifying a Directory
If you know where to look, specify the path.
Starting from the Root Directory
You can also start from the root of a drive.
Running from the root produces very long output. Narrow the starting path to the range you need.
Can You Limit the Depth?
The only main options of the Windows tree command are /F and /A.
There is no built-in way to specify a depth such as tree -L on Linux.
To see fewer levels, start from a deeper path. For a tree to paste into a document, output everything and then limit the depth with the tree formatter.
In PowerShell, -Depth of Get-ChildItem limits how many levels are searched.
Get-ChildItem -Recurse -Depth 1
-Depth 1 shows the folder’s direct contents plus one more level. The output is a per-folder list rather than a tree with line characters.
Options of the tree Command
| Option | Description |
|---|---|
/F | Also display file names in each directory |
/A | Use ASCII characters instead of line-drawing characters |
/? | Display help |
/F - Show Files
By default only folders are displayed. With /F, the file names in each folder are shown too.
/F shows folders and files together, which makes it easy to document a project structure.
/A - Use ASCII Characters
The default output uses line-drawing characters. /A switches to ASCII characters.
When pasting into a text file or Markdown, ASCII characters are less likely to break depending on the environment. Add /A when saving for sharing.
Combining /F /A
To include files and use ASCII characters, combine the options.
Practical Examples
Saving the Output to a File
You can save the output of tree with redirection.
This saves the directory structure to structure.txt. If the path contains spaces, wrap it in double quotes, as in tree "C:\My Projects\MyApp" /F /A.
When pasting the saved file into email, chat, or Markdown, using /A too helps avoid garbled characters.
Viewing One Screen at a Time
For long output, combine it with more.
Press Space for the next screen or Enter for the next line. Press Q to stop.
Checking a Development Project Structure
Folders with many files, such as node_modules, make the output huge. tree has no exclude option, so start from a narrower path, or paste the output into the tree formatter and exclude folders there.
Finding Specific Files
tree shows the overall structure and cannot filter by name. To search by extension, use dir with subfolder search.
/s includes subfolders, and /b prints only the paths.
Difference from the dir Command
tree and dir both show files and folders, but they are good at different things.
| Item | tree | dir |
|---|---|---|
| Display format | Tree structure | List |
| Readability of hierarchy | High | Low |
| File details | Names only | Size, date, attributes, etc. |
| Best for | Checking structure, documentation | Checking details, filtering |
Use tree to see structure and dir to see details.
Summary
This article covered the following points about the tree command.
treedisplays the folder structure in tree form/Falso shows file names/Aswitches to ASCII output- The standard Windows
treehas no option to specify depth or exclusions (paste the output into the tree formatter to do both) - Use
/Aas well when saving to a file for sharing