How-To Guide

    Tree Command in Windows: Show and Save a Folder Structure

    Every switch of the built-in tree command, the examples you will actually use, how to export the tree to a text file without garbled lines, and what to do when you need a depth limit.

    Published October 25, 2026Updated October 25, 20266 min read
    Mehrab Ali

    Author

    Mehrab Ali

    Founder & Executive Lead, ARCED International

    Founder of ARCED Foundation, ARCED International, and Solutions of Things Lab (SoTLab). Built FolderManifest to help teams protect file integrity and stay audit-ready.

    Quick Answer

    The tree command shows the folder structure of a path in Command Prompt. Run tree for folders only, tree /f to include files, and tree /f /a > tree.txt to save the whole structure to a text file that opens cleanly in Notepad. It works the same on Windows 10 and Windows 11.

    tree has shipped with Windows since the DOS days and needs nothing installed. It is the fastest way to see, document, or share how a folder is laid out, for a README, a support ticket, or a hand-off to a colleague.

    Tree Command Syntax and Switches

    tree [drive:][path] [/f] [/a]
    PartWhat it does
    [drive:][path]The folder to map. Leave it out to start from the current folder.
    /fLists the files inside each folder, not just the folders.
    /aDraws the lines with ASCII characters (+, \, -, |) instead of box-drawing characters. Use it whenever you save or copy the output.
    /?Shows the built-in help.

    That is the full list. Windows tree has no option for depth, hidden files, sizes, or excluding folders; see the workarounds below if you need those.

    Tree Command Examples

    Open the folder in File Explorer, click the address bar, type cmd, and press Enter. Command Prompt opens in that folder. Then:

    :: Folders only, from the current folder down
    tree
    
    :: Folders and files
    tree /f
    
    :: A specific folder (quote paths with spaces)
    tree "C:\Users\Me\Documents\Projects" /f
    
    :: A whole drive (can take a while)
    tree D:\
    
    :: Read a long tree one screen at a time
    tree /f | more

    Output for tree /f /a on a small project folder looks like this:

    Folder PATH listing for volume OS
    Volume serial number is 1A2B-3C4D
    C:.
    |   README.md
    |
    +---docs
    |       guide.pdf
    |
    \---src
        |   main.js
        |
        \---assets
                logo.png

    The first two lines are a header tree always prints. C:. means "the current folder". Files in a folder are listed before its subfolders.

    Save the Folder Tree to a Text File

    :: Save to a file in the same folder
    tree /f /a > tree.txt
    
    :: Save to the Desktop so tree.txt isn't part of the listing
    tree /f /a > "%USERPROFILE%\Desktop\tree.txt"
    
    :: Copy to the clipboard instead
    tree /f /a | clip

    > replaces the file each time; use >> to add to the end of an existing file. If you save inside the folder you are mapping, tree.txt itself appears in the listing, so writing to the Desktop keeps the output clean.

    Need names with sizes and dates rather than a drawing? Our guide to printing a list of files in a folder covers dir, PowerShell to CSV, and Excel's From Folder.

    Fix Garbled Characters in tree.txt

    Run tree /f > tree.txt without /a and open the file, and the lines often look like ÃÄÄÄdocs or ÀÄÄÄsrc. tree draws its default lines with characters from the old console code page, and most editors read the file with a different encoding.

    The fix is to add /a. The structure is identical; only the line characters change. This matters even more in PowerShell, which re-encodes output it redirects, so tree /f /a > tree.txt is the safe form in both shells.

    Limits of tree and How to Work Around Them

    Limit the depth with PowerShell

    Windows tree always goes all the way down. In PowerShell (5.0 or later), -Depth stops after a set number of levels. This prints an indented outline two levels deep:

    $base = (Get-Location).Path.TrimEnd('\').Split('\').Count
    Get-ChildItem -Recurse -Depth 1 |
      Sort-Object FullName |
      ForEach-Object { ('    ' * ($_.FullName.Split('\').Count - $base - 1)) + $_.Name }

    -Depth 1 means the current folder plus one level of subfolders. Add -Directory after -Recurse for folders only, or pipe to Out-File "$HOME\Desktop\tree.txt" to save it.

    Skip folders like node_modules or .git

    tree cannot exclude anything. In PowerShell, filter the list before printing it, for example Get-ChildItem -Recurse -File | Where-Object FullName -notmatch '\\node_modules\\|\\.git\\' | Select-Object FullName. Developers who need this often install a port of the Linux tree, or run it in WSL, where tree -I 'node_modules|.git' does it in one step.

    No sizes, dates, or hidden-file control

    tree prints names only. For sizes and modified dates use dir /s or PowerShell's Select-Object FullName, Length, LastWriteTime.

    The tree Command on Mac and Linux

    The Unix tree is a different program with many more options. macOS does not include it; install it with brew install tree. On Ubuntu or Debian, run sudo apt install tree (Fedora: sudo dnf install tree).

    tree                        # folders and files (files are shown by default)
    tree -d                     # folders only
    tree -L 2                   # stop after 2 levels
    tree -a                     # include hidden files
    tree -I 'node_modules|.git' # skip matching names
    tree -h                     # show sizes
    tree --charset ascii        # ASCII lines, like /a on Windows
    tree -o tree.txt            # write to a file

    Note the difference: Unix tree lists files by default, while Windows needs /f.

    When a Folder Tree Isn't Enough

    A tree tells you what a folder looks like. It can't tell you whether the files in it are the right ones. After copying a project to a new drive or restoring a backup, two trees can match line for line while a file was cut short, corrupted, or replaced by an older version with the same name.

    FolderManifest builds a folder manifest instead: every file with its path, size, dates, and a SHA-256 hash, exported as HTML, CSV, or Markdown. Verify a copy, or the same folder a month later, against that manifest and it reports exactly which files were added, removed, or changed. It runs locally on Windows 10/11, macOS, and Linux.

    You may not need it

    If you only want a picture of the folder layout, tree /f /a is all you need. A manifest is worth it when you have to prove a copy is complete and unchanged.

    Checking two folders right now? Follow our guide to comparing two folders on Windows, or read what goes into a folder manifest.

    Frequently Asked Questions

    What does the tree command do in Windows?

    tree draws the folder structure of a drive or path as an indented graph in Command Prompt. By default it shows folders only. Add /f to include the files in each folder, and /a to draw the lines with plain ASCII characters instead of box-drawing characters.

    How do I save the tree output to a text file?

    Run tree /f /a > tree.txt in the folder you want to map. The > sends the output into tree.txt instead of the screen. Use /a when saving, because the default line characters often show up as garbled symbols when the file is opened in another program.

    Why does my tree.txt file show strange characters?

    Without /a, tree draws its lines with characters from the old console code page. When that file is opened as a normal text file, the lines turn into symbols such as à and Ä. Re-run the command with /a so it uses +, \ and - instead.

    Can I limit how deep the tree command goes?

    No. Windows tree has only the /f and /a switches, with no depth limit and no way to exclude folders. For a limited depth, use PowerShell Get-ChildItem with -Depth, or install a port of the Linux tree command, which supports -L for depth and -I to exclude folders.

    Does the tree command work in PowerShell?

    Yes. tree is a separate program (tree.com), so typing tree /f in PowerShell runs the same command as in Command Prompt. When redirecting the output to a file in PowerShell, keep /a so the lines survive the change in text encoding.

    Is there a tree command on Mac or Linux?

    Most Linux distributions offer tree as a package (sudo apt install tree on Ubuntu or Debian). macOS does not include it; install it with Homebrew using brew install tree. That version adds options Windows lacks, such as -L 2 for depth, -a for hidden files, and -o to write to a file.

    Go From a Folder Tree to Proof

    Record every file with its SHA-256 hash, then check any later copy against it. Windows, Mac, and Linux. 7-day free trial, no card required, 30-day money-back guarantee.

    Continue Learning