How can I copy the names of files in a directory to a text file or to a clipboard?
It's very, very easy in the Windows Command-Line Interpreter (all Windows OSes):
- Open a command prompt (Start -> Run ->
- Navigate (
cd) to the directory whose files you want to list.
dir > output_file_name(e.g.,
dir > C:\dir.txt) and press Enter.
Open the newly created text file (
C:\dir.txt) and you'll have the complete output of the
dir command in that directory.
The greater than symbol (
>) signifies output redirection; it sends the output from most commands to a file you specify and is very handy for being able to log output from commands.
The output can be controlled with all the various options available for customizing the normal output of the DIR command; just add the output redirection at the end of whatever arguments you want to send that output to the text file.
Update: Creating a right-click context menu for creating directory contents listing
Create a batch file and save it as
@echo off set dirpath=%1 dir %dirpath% /-p /o:gn > "%dirpath%\DirContents.txt" exit
Create a new shortcut pointing to
DirList.bat and call it whatever you please.
Now, right clicking on any directory and selecting the
SendTo sub-menu will present your new command for listing directory contents.
NOTE: This will only work when right-clicking on a directory, and it will only list the contents of the directory you right-clicked on. It also saves the list to that directory (to avoid overwriting other files). The script could be easily modified to change where the output list file is stored.
From Windows' file explorer, create a shortcut in the SendTo folder and type the following command:
%windir%\system32\cmd.exe /k dir /b "%1"
remove the "Start in" text
After the command was run once, you can change the defaults for the window (such as selction with mouse, instead of Edit → Mark).
The only problem is that you will need to ignore the first line (that says "file not found").
I had a Google drive folder of audio clips that needed to be put into a web-archive. To do that, I needed a spreadsheet of the complete file paths.
Writing a Google script to list the files into a Google spreadsheet didn't work because of timeouts due to the large number of files.
So I downloaded the folder and combined the answers above to list the files and folders in an easy-to-process list that could be pasted into Excel and manipulated further:
dir /s /b > filelist.txt
If you don't add the
/b option, it groups files by the sub folder and using that data in Excel becomes cumbersome