How to export the directory tree of a folder in Windows
Have you ever needed to export the entire directory tree from a certain folder? Did you need to get a text document that lists all the files and folders inside a specific folder from your computer into a hierarchical structure? We had this need when we were trying to create a document that was supposed to be a summary of all the Word documents and Excel spreadsheets we had stored inside a folder. It was at that time that we asked ourselves: how can you automatically create a text file that lists the entire directory tree and all the files inside a folder. After doing a bit of research, we found a simple way to do it and now we want to share it with you. Read on to find how to export a folder structure in Windows:
NOTE: To show you all the steps you'll have to t ake , we're going to export the directory tree of a folder called Data found on our F partition. This guide works on all versions of Windows, including Windows 7, Windows 8.1 and Windows 10.
Step 1. Navigate to your folder and open the Command Prompt
The first thing you must do is use the Windows/File Explorer navigate to the folder for which you want to export the directory tree. In our case, that would be "F:\Data".
Open that folder.
Then, type "cmd" in the address bar of Windows/ File Explorer 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 our case, the Command Prompt was opened using the "F:\Data" folder, as you can see below.
NOTE: If you want to export the directory tree of a folder that contains system files or folders, you will have to launch a Command Prompt with administrative rights and then navigate to your folder from the Command Prompt itself. To open Command Prompt as admin, follow this tutorial: 7 Ways To Launch The Command Prompt In Windows. If you need help on how to navigate to your folder from within the Command Prompt , you should also read the first section of this tutorial: Command Prompt - How to Use Basic Commands.
Step 2. Run the "Tree" command
This is the most important step in our tutorial. To get the hierarchical list of folders and files inside your specified folder, you'll have to run the "tree" command. In the Command Prompt window, type: "tree /a /f > output.doc".
Note that "output.doc" is the document file in which the entire directory tree will be saved. You can use any name for it and you can specify any file type as long as it is a text format. We 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.
Once you made sure that the command is written correctly, press Enter on your keyboard. Depending on how many folders and files are stored inside your folder, running this command can take a moment or two.
Step 3. Get the text file with your directory tree
Now you can safely close the Command Prompt , as you don't need it anymore. Go back to Windows/File Explorer and navigate to the folder for which you wanted to export the directory tree. Inside, you will find a the new text file with the name you specified in the "tree" command. In our case, this file is named "output.doc".
Open the output file and the entire directory tree is listed inside. It looks good, doesn't it?
I'm feeling geeky right now! :)
As you can see, exporting the entire directory tree structure to a text file is easily done in Windows. All you need is the Command Prompt and the right command. If you have any questions on this subject, don't hesitate to ask below, in the comments form. We'll do our best to help.