Home » Tech Tips » Windows » How to Download Tree View of Folders in Windows PC?

How to Download Tree View of Folders in Windows PC?

Window PC comes with a default File Explorer also known as Windows Explorer. This helps to view or open files quickly in Windows operating system (similar to Finder in macOS). You can navigate through the folders using back, forward or up icons located on the top left side of the address bar, directly entering location in the address bar and using left or right panes. But all these options will not give you a complete structure of a folder showing the files and sub-folders inside as a tree view. In this guide, we will show you how to use tree command in File Explorer and in the Command Prompt to download the tree view of any folder in Windows.

What is Tree View?

Let us take an example of a Bootstrap project folder like below having different folders for CSS stylesheets and JavaScript (JS) files.

bootstrap/
├── dist/
│   ├── css/
│   └── js/
├── docs/
│   └── examples/
├── js/
└── scss/

The structure could also be more complex like below that each folder may have multiple files.

bootstrap/
├── css/
│   ├── bootstrap-grid.css
│   ├── bootstrap-grid.css.map
│   ├── bootstrap-grid.min.css
└── js/
    ├── bootstrap.bundle.js
    ├── bootstrap.bundle.min.js
    ├── bootstrap.bundle.min.js.map
    ├── bootstrap.js
    ├── bootstrap.min.js

There are no ways in File Explorer, you can understand the entire structure of a folder or directory. Every time you should use navigations to move up or down to find a file. It is essential in a project to have files under correct folder and use the relative path when linking files in other documents. Here comes the use of tree structure. There is a ‘Tree’ command in Windows which allows you to view the files/folders in a tree-like structure. You can also download the structure of any folder using tree command and use for reference.

Download Tree View of Folder in Windows

There are two ways to get the tree structure of a folder:

  • Using tree command in File Explorer
  • Get tree structure from Command Prompt

1. Download Tree Structure in File Explorer

This is not a direct way of viewing the folders/subfolders/files in File Explorer in a tree format. Tree command works in File Explorer but in a slightly different way. It uses the Command Prompt to create a file for the tree view. Let’s see how to do this.

  • Press ‘Windows Logo + E’ shortcut keys and open the File Explorer or open it by double clicking ‘This PC’ icon on your desktop. Navigate to the folder from where you want to perform this command or to view its structure. In our case, we go to ‘SWSetup’ folder.
  • Go to the address bar and type the command like below:
CMD /c "Tree /F /A > Resultant.txt"
Tree Command to Create a File
Tree Command to Create a File

Syntax of Tree command:

cmd /c TREE [Drive:][Path] [/F] [/A]
  • cmd /c is used to trigger Command Prompt.
  • Tree is the command name to generate the structure.
  • /F is to list down the list of all the files in every folder. Without this parameter only folders without files will be listed.
  • /A for exporting the result in a file.
  • > Resultant.txt is the name of the file in text format, you can also use something like tree.doc to generate the file in document format.
  • Press enter key from the keyboard. After this, a new file with the name ‘Resultant’ will be created in the SWSetup folder.
  • Double-click on the file and you can be able to see the structured tree format of all files in SWSetup folder.
Resultant Tree View of Directory
Resultant Tree View of Directory

You can generate the tree structure for any specific folder. For example, if the folder is located in ‘D:\test’, then you should use the below command in the File Explorer address bar. It will generate a ‘tree.doc’ file in ‘D:\test’ folder.

cmd /c "tree D:\test /f /a > tree.doc"

2. View or Download Tree Structure Using Command Prompt

Now, you can use the Tree command in Command Prompt and can view the tree structure format of all the files right there. Follow the steps given below:

  • Go to the ‘Start’ menu, type ‘Command Prompt’ and press enter key from the keyboard.
  • Type ‘CD’ command in the prompt and then give the path of the folder/subfolder/drive for which you want to get the tree view. In our case, it’s our user folder so, the path would be (CD C:\users\username).

Here, you can use the ‘Tree’ command in two ways. The first way is to simply use the command directly to view the file structure. However, the issue with this approach is that if there are too many files, you may not be able to see all of them at once as the output keeps scrolling down. The second way is to export the file structure to a plain text file, as we have done before, but this time using the Command Prompt (CMD).

  • For a quick view, navigate to the folder/drive for which you want to see the structure. Type the ‘Tree’ command in the prompt and press enter key. Make sure you’re using this command where the number of folders are less to view the structure clearly.
Simple Tree Command to View Files
Simple Tree Command to View Files
  • To download the content in a separate file, type ‘tree /f /a > Resultant.txt’ and press enter key. Now, go back to the folder and you will find a file generated with a name ‘Resultant.txt’. Open the file to see a clean structured tree format of the selected folder.

You can also use Windows PowerShell instead of Command Prompt to view the tree structure of any folder.

3 thoughts on “How to Download Tree View of Folders in Windows PC?”

  1. Christopher Benson

    I have a couple of minor corrections for your article on the TREE command.

    (1) Your article states that in the TREE command, the /A option is “for exporting the result in a file”.
    That is not correct. The /A option formats the output using 8-bit ASCII characters instead of the default 16-bit UNICODE characters.
    If you use TREE /A, you won’t see file names that use non-ASCII characters
    (such as “చాలా ధన్యవాదాలు.docx” or “π.txt” (pi dot text)).

    The TREE command does not have an option to export the results to a file. Of course, as your article did correctly note, the Windows command prompt syntax allows you to do that for any command just by adding a redirect clause to the end of the command line, as in “> Resultant.txt” (without the double quotes). But the TREE command isn’t redirecting the output to a file, the command line module itself is doing that.

    (2) Your article states that “> Resultant,txt” will produce a file called “Resultant”.
    It won’t. It will produce a file called “Resultant.txt”, just like you asked for.

    (3) Your article states that you can get the output of the TREE command in “document format” just by redirecting the command’s output thus “> Resultant.doc”. Computers would be nicer if that kind of thing were true, but sadly it’s not. As always and with all commands on all the operating systems I have known in fifty years, redirecting the command’s output with “> Resultant.doc” will create the same identical file as was created with “> Resultant.txt”. The second file will just be called “Resultant.doc”, a name that is unsuitable and misleading because “.doc” is the wrong file extension for its text-only type.

Leave a Comment

Your email address will not be published. Required fields are marked *