How to export a folder tree to a file (including Excel)

Diposting pada

How to export a folder tree to a file (including Excel)-Digital Citizen UP

Do you need to export the entire directory tree from a specific folder? Do you need to get a text or Excel document that lists all the files and folders within a specific folder from your computer in a hierarchical structure? I need this while trying to create a document that is supposed to be a summary of all the Word documents and Excel spreadsheets I have stored in a folder. It was at that point that I asked myself a few questions. Can you automatically export the folder structure to Excel? Is there a DOS tree command that generates files? Can you print the directory tree into an Excel sheet or as a text file? If you want to know how to export folder hierarchies, read on:

NOTES: In this guide, I present two methods for exporting a folder tree file. The first is based on using the Command Prompt to generate a directory tree as a text file, while the second relies on an executable file (a script created with PowerShell) that displays 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 polder tree is a graphical layout or representation of the hierarchical structure of folders and files found within a parent folder. A directory tree is useful when you want to see how folders and files are organized within a parent folder, helping you navigate and manage data more efficiently.

What the folder structure looks like in File Explorer

To get a better idea of ​​what a folder tree is, think of a family tree, but for folders on a computer. Imagine a root folder, let’s call it Parent Folder, which contains files as well as other Child Folders. Each of those Child Folders can have other Grandchildren’s folders and files stored in them, and so on, and so on. Subfolders can have their own subfolders, creating a nested folder structure.

The folder tree is a graphical layout of the directory structure

How to get folder tree structure in Windows

Now that we know what a folder hierarchy is, let’s see how to create one:

1. Export the folder structure to a text file using the “tree” command in Command Prompt

First, open File Explorer and navigate to the folder where you want to export the directory tree. To illustrate the process, I’ll use my Games folder, located at “E:\Games”.

Use File Explorer to enter the folder

Type cmd in the File Explorer address bar and press Enter to open a Command Prompt directly in the folder you are interested in.

Opens a Command Prompt in a folder location

A Command Prompt instance opens, pointing to your folder. In my case, Command Prompt opened using “E:\Games” folder. To export the folder structure, run this command:

tree/a/f > output. doc

Executed the tree command to get the folder structure

TIP: If you don’t want the directory tree to include files (in other words, make the tree include only folders), skip it /f from the command (tree/a > output.doc).

Output.doc is the document file where the entire directory tree is stored. 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 to use a Microsoft Word .doc file, but you can use any other text file. For example, you can choose to output a directory tree to a simple.txt file that can be edited with Notepad. Depending on how many folders and files are stored in your folder, running this command can take a moment or two.

The tree command can take a while if the folder you run it from has a lot of items

You can now close Command Prompt, since you don’t need it anymore. Return to File Explorer and navigate to the folder you want to export the directory tree to. Inside, you should find a new text file with the name you specified in the tree command. In my case, this file is called output.doc.

Output text file with folder/file tree

Open the output file, and the entire directory tree is listed in it.

Polder in the document file

NOTES: If you want to export a folder directory tree containing system files or folders, you must launch Command Prompt with administrative privileges and then navigate to your folder from the Command Prompt itself.

2. Export folder structure to Excel (XLS or CSV file) with our FolderTree tool (based on PowerShell)

Another way to export folder structure in Windows is to use a tool that was actually created by you. It’s called FolderTree, and you can download it use this link or the one at the end of this chapter. If you want you can also check the code 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.

Place FolderTree in the folder whose directory tree you want

NOTES: When you launch FolderTree for the first time, the SmartScreen filter may warn you that it is an unknown application. That’s because not many people download and use it. Trust that it is safe and does no harm to your PC. It’s nothing more than a PowerShell script inside an executable file and a simple user interface. If you get a warning, click or tap “More info” and select “Run anyway.”

When FolderTree opens, you will see a small window like the one below. To get a directory tree of the current folder, hit the “Get folder tree to Excel” button.

Get Folder Tree to Excel

The tool then displays two files: FolderTree.xlsx and FolderTree.csv. Both contain a hierarchical list of folders and files within your current directory.

FolderTree outputs a directory tree in Excel and inside a CSV file

Additionally, both files must have two columns: Directory and Name. The Directory column tells you the folder and the Name column tells you the files in that folder.

Exported directory tree in Excel

Now you can go ahead and edit the Excel or CSV file with the folder tree as you wish. If you encounter any issues with our tool, let me know in the comments section below.

NOTES: An important limitation of using this script/file is that you can’t use it if you have a very long file path. To be honest, this actually is Microsoft Excel limitations than PowerShell from FolderTree executable/script. Excel doesn’t allow file links longer than 256 characters, which limits the number of characters for path names to 218.

Why do you need to export a folder directory tree?

Exporting the entire directory tree to a text file is fast in Windows. All you need is Command Prompt and the right commands. Exporting a directory tree to Excel is also easy using our FolderTree tool. Before closing this article, tell me why you want to create a file folder tree. Is it because you want to list your music files? Is it for a work-related task? Comment below, and let’s discuss.

Related article


Thus the article about How to export a folder tree to a file (including Excel)
I hope the information in the article is useful to you. Thank you for taking the time to visit this blog. If there are suggestions and criticisms, please contact us :