How to copy a list of file names to text file?

Solution 1:

It's very, very easy in the Windows Command-Line Interpreter (all Windows OSes):

  1. Open a command prompt (Start -> Run -> cmd Enter)
  2. Navigate (cd) to the directory whose files you want to list.
  3. Enter 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 %windir%\DirList.bat:

@echo off
set dirpath=%1
dir %dirpath% /-p /o:gn > "%dirpath%\DirContents.txt"
exit

Open your SendTo directory:

Windows 7/Vista: %appdata%\Microsoft\Windows\SendTo
Windows XP: %USERPROFILE%\SendTo

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.

Solution 2:

You can use dir /b > files.txt from the command-line to get the list of filenames stored into files.txt. Add a /s if you want a recursive listing.

To place the contents directly onto the clipboard, just pipe the output to clip, i.e execute dir /b | clip.

Solution 3:

Since you did not mention an operating system, here is how it is working on *nix:

$ find . -maxdepth 1 -type f > /tmp/files.txt

for files in the current directory or

$ find . -type f > /tmp/files.txt

if you want to get all files in a directory tree.

Solution 4:

Another Unix variant would be

ls -R > myfile.txt 

This would list everything in the current directory and recursive directories.