How to Get All File Names in a Folder via CLI and File Explorer Windows

User Author

Achilles.H

January 15, 2024

How to Get All File Names in a Folder via CLI and File Explorer Windows

When you want to make a file list or record related information during the backup process, you may have questions like this: What can I do to quickly get all file names in the folder and its subfolders? If you want to find out the answer to this, how to get all file names in a folder via CLI and file explorer Windows is just written for you. I will introduce two types of ways to you, one is use some commands, the other is copy and paste in batches via windows explorer or browser. Let's watch.

1. Ways to get all file names in a folder and subfolders

Way 1: Use dir command in command prompt

Step 1: Open the File Explorer and locate the folder that you want to get all file names in.

Step 2: Open the Command Prompt via inputting "cmd" in the address bar of the File Explorer. (You can also open command prompt by other ways and use "cd custom path" to switch to the directory you want to get filenames.)

open command prompt

Step 3: Run "mkdir D:\filename" to create a directory you want to store export file. (You can also select a existing directory to store export file in the next step.)

mkdir D:\filename

Step 4: Run "dir /B/S > D:\filename\filenames.txt" (You can select the directory you like to store the export file.)

dir /B/S > D:\filename\filenames.txt
mkdir and dir

Step 5: Now navigate to the output directory you specified previously, you will see the filenames that contain the path information in the filenames.txt.

dir demo

Tips: You can get more information about "dir" command via running "dir /?" or "help dir" command.

dir /?help dir dir help

Way 2: Use Get-ChildItem command in Windows Powershell

Step 1: Navigate to the folder that you want to get all file names in.

Step 2: Press and hold the Shift key then right-click in the blank space of the page, and select "Open PowerShell windows here" in the context menu.

open powershell

Step 3: Run "Get-ChildItem -File -Recurse | Select-Object Name > D:\filename\filenamespowershell.txt" in Windows Powershell

Get-ChildItem -File -Recurse | Select-Object Name > D:\filename\filenamespowershell.txt
get-childitem in powershell

Notes: You can see more details about this command in Get-ChildItem.

Step 4: Navigate to the output directory and you can see the corresponding file here.

get-childitem demo

Way 3: Use tree command to get hierarchical information

If you want to see the hierarchy of files more intuitively, this approach may work better for you.

Step 1: Open the Command Prompt via performing the same operations as way 1.

Step 2: Run "tree /F > D:\filename\filenamestree.txt" command.

tree /F > D:\filename\filenamestree.txt
tree in cmd

Step 3: Find the corresponding file in your specified file path. The effect is as shown in the picture.

tree demo

Way 4: Use "Copy path" function provided by Windows File Explorer

Step 1: Locate to the directory that contains all files and subfolders you want to get all file names in.

Step 2: Input dot(.) in the search bar of File Explorer, then all files in this folder and its subfolders will appear.

file explorer display all items

Step 3: Select all files you want to get filenames for.

Tips: "Ctrl + A" -> check all items shown.

Press and Hold "Ctrl" key, then click on the item-> check or uncheck item.

Step 4: Select "Home" -> "Copy path", then the full path of the selected file will be copied to the clipboard.

Copy path

Step 5: You can paste it to the workbook or other locations you want.

Step 6: If you paste it to the workbook, you can further process it via "Find and Replace" function provided by Excel.

process information in excel

Tips: "Ctrl + H" can open "Find and Replace" dialog quickly.

Way 5: Batch copy and paste through browser

What's more, you can batch copy and paste through browser. It is worth noting that this way can not get filenames in subfolders directly. If you need get filenames contained in subfolders, choose the method mentioned earlier.

Step 1: Copy the path of directory that you want to get filenames in.

browser copy path

Step 2: Paste the path into your browser's search box, and hit "Enter".

Step 3: The file information will be displayed, then you can copy information you wanted.

browser demo

2. Conclusion

This article provides five ways for you to get all file names in a folder. It is worth mentioning that it is best to execute the relevant commands in the command line tool corresponding to the article instructions. Some commands may not be compatible with other CLI. Hope this article can help you.