To export a file directory to Excel, the fastest method is using the Command Prompt (CMD) on Windows to generate a text list of files, which can then be imported directly into an Excel spreadsheet. This process allows you to catalog thousands of files, including their names, sizes, and modification dates, without manually typing each entry. This is particularly useful for auditing server backups, organizing large media libraries, or creating a manifest for project handovers.
What You'll Need
- A computer running Windows (this guide focuses on the Windows Command Prompt method).
- Microsoft Excel installed on your system.
- Administrative access to the folders you wish to export (if the folders are system-protected).
- A basic understanding of how to navigate folders on your hard drive.
Step-by-Step
- Open the Target Folder: Navigate to the folder you want to export using Windows File Explorer. Once you are inside the folder, click on the address bar at the top of the window. The path (e.g., C:\Users\Name\Documents\Project) will be highlighted.
- Launch Command Prompt from the Folder: While the address bar is highlighted, type
cmdand press Enter. This opens the Command Prompt window already pointed at that specific directory, saving you from having to use thecd(change directory) command manually. - Run the Directory Command: In the black Command Prompt window, type the following command exactly as shown:
dir /s > filelist.txt.dirtells the system to list the files in the directory./sis a switch that tells Windows to include all files in subdirectories (recursive search). If you only want the files in the immediate folder, omit the/s.>is the redirection operator; it tells the computer not to print the list on the screen, but to send the output to a file.filelist.txtis the name of the text file that will be created. You can name this whatever you like.
- Verify the Text File: Close the Command Prompt window and return to your folder in File Explorer. You will now see a new file named
filelist.txt. Open it with Notepad to ensure the list of files is present. - Open Microsoft Excel: Launch a new, blank workbook in Excel.
- Import the Text File: Go to the Data tab on the top ribbon. Depending on your version of Excel, select Get Data > From File > From Text/CSV. Alternatively, you can simply drag and drop the
filelist.txtfile directly into an open Excel sheet. - Configure the Import Settings: If you used the Get Data method, a preview window will appear. Excel will attempt to detect the delimiter. Since the
dircommand creates a space-separated list, you may need to select Fixed Width or Space as the delimiter to separate the date, time, and file size into their own columns. - Load the Data: Click Load. Your file directory is now populated in the Excel spreadsheet.
- Clean Up the Data: The
dircommand includes header and footer information (like "Volume in drive C" and "Total files listed"). Select the rows containing this unnecessary text, right-click, and choose Delete to leave only the actual file data.
Common Mistakes
One of the most frequent errors is forgetting to run the Command Prompt from the correct directory. If you open CMD from the Start menu, it usually defaults to your user profile folder (C:\Users\YourName). If you run the dir command there, you will export your entire user profile instead of the specific project folder you intended. Always use the address bar trick to ensure you are in the right location.
Another common mistake is using the wrong redirection symbol. Some users mistakenly use < instead of >. The > symbol pushes data out of the command and into a file. Using < tells the command to read input from a file, which will result in an error or no output at all.
Users also often forget to include the /s switch when they actually need a full inventory of nested folders. Without /s, you only get a "flat" list of the top-level folder. Conversely, adding /s to a drive with millions of files (like the C: drive root) can create a text file so large that Excel struggles to open it or the Command Prompt hangs for several minutes.
Tips
To get a cleaner list that only contains the file names without the date, time, or size, use the dir /b command. The /b stands for "bare" format. If you want both subdirectories and a clean list of names, use dir /s /b > filelist.txt. This is the most popular option for people who only need a list of paths for a database or a checklist.
If you are dealing with files that have special characters or non-English alphabets, the standard dir command might produce garbled text in the .txt file. To fix this, type chcp 65001 in the Command Prompt before running the dir command. This changes the active code page to UTF-8, which supports a wider range of international characters.
For those who need more detail, such as file attributes (Hidden, Read-only, System), the dir command is sufficient, but you can also explore the tree /f /a > structure.txt command. While dir gives you a list, tree gives you a visual representation of the folder hierarchy, which is excellent for documentation, though harder to sort in Excel.
Troubleshooting
The filelist.txt file was not created: First, check if you have write permissions for that folder. If the folder is in C:\Program Files or C:\Windows, Windows will block the creation of a new text file for security reasons. Move the folder to your Documents or Desktop, or run the Command Prompt as an Administrator by right-clicking the CMD icon and selecting Run as administrator.
Excel puts everything into one column: This happens because the dir command uses multiple spaces to align columns, and Excel doesn't always recognize this as a consistent delimiter. To fix this, highlight the column containing the data, go to the Data tab, and select Text to Columns. Choose Fixed width and manually set the break lines between the date, time, and filename. This gives you total control over how the data is split.
The command prompt says "Access is Denied": This usually occurs when the dir /s command tries to enter a protected system folder (like "System Volume Information") that even an administrator cannot access. This is normal. The command will skip the protected folder and continue listing the ones it can access. You can ignore these errors as long as the rest of the files are being exported.
The text file is empty: Ensure you didn't accidentally use a file name that already exists and is open in another program. If filelist.txt is open in an editor that locks the file, CMD cannot write to it. Close all text editors and run the command again.
Frequently Asked Questions
Can I export the directory to Excel on a Mac?
The dir command is specific to Windows. On a Mac, you can use the Terminal and type ls -R > filelist.txt. The ls command lists files, and -R makes it recursive. You can then import this .txt file into Excel using the same Data import steps.
How do I export only specific file types, like only .jpg files?
You can use a wildcard in your command. Instead of dir /s > filelist.txt, use dir *.jpg /s > filelist.txt. This tells Windows to only look for files that end with the .jpg extension.
Is there a way to do this without using the Command Prompt?
Yes, you can select all files in a folder (Ctrl+A), hold the Shift key, right-click, and select Copy as path. You can then paste this list directly into Excel. However, this method does not include file sizes or dates, and it is much slower for very large directories with many subfolders.
Will this process move or delete any of my files?
No. The dir command is a "read-only" operation. It simply looks at the metadata of your files and writes that information into a separate text file. Your original files remain untouched and in their original locations.
Can I include the folder size in the export?
The standard dir command lists individual file sizes but does not calculate the total size of a folder. To get folder sizes, you would need a third-party disk analysis tool or a complex PowerShell script, as the basic Command Prompt does not have a built-in "folder size" switch.