Automatically Generate List of File Names Inside Folders and Save as Text File with Windows CMD or PowerShell
In this article, we will cover how to automatically generate a list of file names inside folders and save them as a text file using Windows Command Prompt (CMD) or PowerShell. This can be a useful technique for inventorying files in a directory, backing up files, or preparing to transfer files to another location.
Using Windows Command Prompt (CMD)
To generate a list of file names inside a folder using Windows Command Prompt (CMD), follow these steps:
- Open the Command Prompt by typing
CMDin the Windows Explorer address bar and hitting Enter. - Navigate to the folder where you want to generate the list of file names by using the
cdcommand. - Type the following command to generate a list of file names inside the current folder:
dir /b /a-d > file\_list.txtThis command uses the dir command to list the files in the current directory, with the following options:
/b: Uses bare format (no heading information or summary)/a-d: Displays files only (does not display directories)> file\_list.txt: Redirects the output to a file namedfile\_list.txt
This will create a text file named file\_list.txt in the current folder, containing a list of file names.
Using PowerShell
To generate a list of file names inside a folder using PowerShell, follow these steps:
- Open PowerShell by typing
powershellin the Windows Explorer address bar and hitting Enter. - Navigate to the folder where you want to generate the list of file names by using the
cdcommand. - Type the following command to generate a list of file names inside the current folder:
Get-ChildItem -File | Out-File file\_list.txtThis command uses the Get-ChildItem cmdlet to list the files in the current directory, and then pipes the output to the Out-File cmdlet to save the list as a text file named file\_list.txt.
In this article, we covered how to automatically generate a list of file names inside folders and save them as a text file using Windows Command Prompt (CMD) or PowerShell. This can be a useful technique for inventorying files in a directory, backing up files, or preparing to transfer files to another location.