Windows: How to Export a Directory Structure to a Text File( Directory Tree )

When working with large projects, network drives, or simply organizing files, it’s often useful to generate a clear overview of your folder structure. Luckily, Windows includes a built-in command called tree that makes this quick and easy.

In this guide, we’ll walk through how to print out your current folder and subfolders into a text document using Command Prompt.


Step 1: Open Command Prompt and Navigate to your Directory Location

  1. Press Windows Key + R, type cmd, and press Enter.

  2. By default, Command Prompt opens in your user folder (for example: C:\Users\YourName).

  3. To move into the folder you want to document, use the cd (change directory) command.

Example:

cd C:\Projects\MyWork

  1. If the folder path contains spaces, place the path in quotation marks.

Example:

cd "C:\My Projects\Work Files"

  1. Once you’re in the correct folder, you can run the tree command. If you are already in the folder you want to document, you can skip changing directories and go straight to Step 2.


Step 2: Run the Tree Command

To generate a directory tree and save it to a text file, use the following command:

tree /f /a > directory_structure.txt

Here’s what each part means:

  • tree → Displays the folder structure in a tree format.

  • /f → Includes the names of all files in each folder (remove this if you only want folders).

  • /a → Uses standard ASCII characters instead of extended ones (better for text files).

  • > → Redirects the output to a file.

  • directory_structure.txt → The name of the file where the results will be saved.


Step 3: Open Your Text File

Once the command finishes running, you’ll see a new file called directory_structure.txt in the same folder. Open it in Notepad, Word, or your preferred text editor to view the full folder and file layout.


Example

If you want to export the structure of a specific folder, such as C:\Projects, you can run:

tree "C:\Projects" /f /a > project_structure.txt

This will generate a complete list of all folders and files under C:\Projects and save them to project_structure.txt.

Example Text File

Folder PATH listing for volume Windows
Volume serial number is 34A7-1C2D
C:\PROJECTS
│   README.txt
│
├───MyWork
│       report.docx
│       data.xlsx
│
├───SourceCode
│   │   main.py
│   │   utils.py
│   │
│   └───Tests
│           test_main.py
│
└───Resources
    │   logo.png
    │
    └───Docs
            manual.pdf
            reference.txt

 

Leave a Reply