Create A List Of Files In Windows

CommandFile Windows might have some fancy tricks up its sleeve, but easily generating a list of files in a given directory isn't one of them. For that, your best bet is heading back to a good old-fashioned DOS prompt.

It's not an uncommon scenario: you want a list of all the documents or photos or music files in a given directory, but not the actual files themselves. Windows will happily show you the file names (in Explorer/My Documents/My Pictures — the label varies depending which version of Windows you use and which shortcut you pick); let you choose which order to sort them in; attach them to an email or compress them into a ZIP file. But within Explorer, it won't actually give you an list of files you can throw in an email or edit (other than taking a screen shot, which isn't very helpful).

Fortunately, there is a simple way of doing this, buried within the DOS command line which Windows has always offered. These days, there's relatively little actual DOS code in the guts of Windows Vista or 7, but the command line remains available. While it's often favoured by keyboard gurus for quite complex tasks, producing a file list is one useful trick even for people who are otherwise very happy in a drag-and-drop universe.

The following is a step-by-step guide to doing this, which assumes that you don't know anything much about DOS commands or the like. Experienced command line users could doubtless use slightly different (and speedier) techniques to get the same result, but this method has the advantage of not requiring that detailed knowledge.

  • Navigate to the directory you want to list the files from (using My Documents or Windows Explorer.)
  • Right-click on the end of the directory name and select 'Copy Address'.
  • Click on the Start button.
  • In the Search box, type cmd and then click OK or hit Enter. This should launch the command prompt, a window with a black background and a cursor waiting for you to type commands. (You can also type cmd into the Run dialog on older Windows versions for the same result.)
  • Type cd and hit the space bar.
  • Right-click next to this with your mouse and select Paste. This will add your previously-copied directory name to the command. Hit the Enter key. This will move you to the directory you're interested in.
  • Update: Commenter David points out below that in Vista there's a faster way to open a command prompt in your chosen directory: hold down Shift, right-click the directory, and select 'Open Command Windows Here'. This lets you skip the first six steps above.
  • To create a basic list of all the files in this directory in a file called list.txt, type this command and hit Enter: dir *.* /b >list.txt
  • To restrict the list to files of a particular type, change the second asterisk (*) to the file type. For instance, this command will only list MP3 files: dir *.mp3 /b >list.txt
  • Close the command window by clicking on the X in the top-right corner.
  • There will now be a file called list.txt in your original directory, containing the names of all the files in that directory, which you can open, copy and edit.

Got your own tactic for building file lists? Share it in the comments.

Lifehacker 101 is a weekly feature covering fundamental techniques that Lifehacker constantly refers to, explaining them step-by-step. Hey, we were all newbies once, right?


Comments

    Dont forget /s to go through all subdirectories
    dir *.mp3 /b /s >list.txt

    You don't need the *.* for all files, just "dir /B > list.txt"
    I also tend to throw a /ON in there to sort by name (and /A to include hidden files when needed).

    dir /B /ON > list.txt

      I'd included the *.* so that it looked consistent with the second example. But brevity does have its advantages!

    Another useful thing is to get a listing of the directory structure

    tree >tree.txt

    or for a listing of the files included as well

    tree /F >tree.txt

    There is a much easier and faster way to create a list of files in Windows. And that is to use DirPrinting - a free application from Majusoft http://majusoft.de/DirPrinting/index_en.htm
    I have used DirPrinting for a number of years and its output can be used in a number of ways. Primarily, I use it for creating, in Excel, a catalogue of downloads I burn to CD's/DVD's. I have 52 CD's each containing a variety of applications and PDF's. It only takes me a couple of minutes or less (usually less) to find the one I need. The output is neat and not as complex as the DOS like print out using the Command Prompt method. The website has good illustrations of the output.

    If you want the command prompt window to automatically open in the directory you specify, simply browse until you can see the directory in Explorer, hold shift, right-click on the directory you want and then select "Open command window here".

    Note that this only works in Vista and above; however, there is also a powertoy addon for XP on the Microsoft website somewhere too.

    I use to have a .vbs script that did this, but would save the list.txt as a list.html.

    This HTML would have links to the directory and files within. (*note to self* Must find script...)

    This is one of the few tasks I still find myself using a command prompt for from time to time.

    As mentioned, /s will also include files in the subdirectories of your starting directory, however this will also include the names of the subdirectories as it comes to them.

    If you only want to include actual files, you can use /a-d to exclude the directory names.

    So, to generate a text file containing all the files in my MP3 collection, I use:

    dir *.mp3 /s /b /a-d > tracklist.txt

    Then I can compare this text file with earlier copies for backups etc.

    Also forgot to mention:

    dir > list.txt

    will save the file names in a new file called list.txt, and happily replace any file called list.txt if it already exists.

    If you want to append the file names to the end of an existing file, use:

    dir >> list.txt

    This might be useful for creating a list of file names from multiple directories in different locations.

    You can make something like that too:

    1: Install Notepad++

    2: Save the next script as de.bat (or your name adding at end .bat), for example de.bat

    dir/b>c:/de.txt
    dir/b>de.txt
    "C:\Bring\Archivos de programa light\Notepad++\notepad++.exe" C:\de.txt

    Save it in the windows directory.

    3: Now from every directory in the OS you can call your "new command" de and autoexecute notepad++ opening automatically ready to use.

    CU.

Join the discussion!

Trending Stories Right Now