Did you ever need to export the entire directory tree from a particular folder? Did you need to get a text or Excel document that lists all the files and folders inside a specific folder from your computer in a hierarchical structure? I needed this when trying to create a document that was supposed to be a summary of all the Word documents and Excel spreadsheets I had stored inside a folder. It was at that time that I asked myself a couple of questions. Can you automatically export a folder’s structure to Excel? Is there a DOS tree command that outputs to a file? Can you print a directory tree into an Excel sheet or as a text file? If you want to find out how to export a folder tree, read on:
NOTE: In this guide, I present two methods to export a folder’s tree. The first one is based on using Command Prompt to generate a directory tree as a text file, while the second relies upon an executable file (a script made with PowerShell) that outputs the folder tree as an Excel file and as a CSV file. You can skip to the part that interests you.
What is a folder tree on a computer?
A folder tree is a graphical layout or representation of the hierarchical structure of folders and files found inside a parent folder. The directory tree is useful when you want to see how folders and files are organized inside the parent folder, helping you navigate and manage data more efficiently.
To get a better idea of what a folder tree is, think about a genealogy tree, but for a folder on a computer. Imagine a root folder, let’s call it the Parent Folder, that contains files as well as other Child Folders. Each of those Child Folders can have other Grandchild Folders and files stored within, etcetera, etcetera. Subfolders can have their own subfolders, creating a nested structure of folders.
How to get the folder tree structure in Windows
Now that we know what a folder tree is, let’s see how to create one:
1. Export a folder’s structure to a text file using the “tree” command in Command Prompt
First, open File Explorer and navigate to the folder for which you want to export the directory tree. To exemplify the process, I’ll use my Games folder, located in “E:\Games.”
Type cmd in File Explorer’s address bar and press Enter to open the Command Prompt directly at the folder you are interested in.
A Command Prompt instance is opened, pointing to your folder. In my case, the Command Prompt was opened using the “E:\Games” folder. To export the folder’s structure, run this command:
TIP: If you don’t want the directory tree to include files (in other words, make the tree include only folders), skip the /f parameter from the command (tree /a > output.doc).
Output.doc is the document file where the entire directory tree is saved. You can use any name for it, and you can specify any file type as long as it has a text file type. I prefer using Microsoft Word .doc files, but you could use any other text file. For instance, you can choose to output the directory tree to a simple .txt file that’s editable with Notepad. Depending on how many folders and files are stored inside your folder, running this command can take a moment or two.
Now you can close the Command Prompt, as you don’t need it anymore. Go back to File Explorer and navigate to the folder for which you wanted to export the directory tree. Inside, you should find the new text file with the name you specified in the tree command. In my case, this file is called output.doc.
Open the output file, and the entire directory tree is listed inside.
NOTE: If you want to export the directory tree of a folder that contains system files or folders, you must launch Command Prompt with administrative rights and then navigate to your folder from the Command Prompt itself.
2. Export a folder’s structure to Excel (XLS or CSV file) with our FolderTree tool (based on PowerShell)
Another way to export the structure of a folder in Windows is to use a tool made by yours truly. It’s called FolderTree, and you can download it using this link. If you want, you can also check the code of the file here: FolderTree on GitHub.
Save the FolderTree file somewhere on your Windows PC. Then, move or copy it to the folder whose tree structure you want to get. In that folder, double-click or double-tap on the FolderTree executable.
NOTE: When you launch FolderTree for the first time, the SmartScreen filter might warn you that it’s an unrecognized app. That’s because there are not that many people downloading and using it. Take my word that it’s safe and does not harm your PC. It’s nothing more than a PowerShell script inside an executable file and a simple user interface. If you get the warning, click or tap on “More info” and choose “Run anyway.”
When FolderTree opens, you should see a small window like the one below. To get the directory tree of the current folder, push the “Get folder tree to Excel” button.
The tool then outputs two files: FolderTree.xlsx and FolderTree.csv. Both contain the tree list of folders and files inside your current directory.
Furthermore, both files should have two columns: Directory and Name. The Directory column tells you the folder and the Name column tells you the files in that folder.
Now you can go ahead and edit the Excel or CSV file with your folder tree as you want. If you encounter any issues with our tool, let me know in the comments section below.
NOTE: An important limitation of using this script/file is that you can’t use it if you have very long file paths. Truth be told, this is actually a Microsoft Excel limitation rather than PowerShell one of the FolderTree executable/script. Excel doesn’t allow file links that are longer than 256 characters, which limits the number of characters for a path name to 218.
Why did you need to export the directory tree of a folder?
Exporting the entire directory tree structure to a text file is quickly done in Windows. All you need is the Command Prompt and the right command. Exporting a directory tree to Excel is also easy using our FolderTree tool. Before closing this article, let me know why you wanted to create a file folder tree. Was it because you wanted to make a list of your music files? Was it for a work-related task? Comment below, and let’s discuss.