Capturing Lists of Files (Windows)

DOS DIRHave you ever needed to obtain a list of all of the files that exist in a folder so that you can document them? Here are some tips for using the DOS DIR command to make quick work of it.

The first thing to do is to open a DOS prompt window, and then navigate to the folder in question using the CD command (CD stands for change directory).

cd c:/tmp/classics

Next, issue the DIR command on a line by itself.

dir

The filenames for that folder will fly by, if there are a lot of them. That’s okay. Just inspect the names at the end of the list to make sure that this is the right folder.

Now, issue the DIR command again, but this time add a space, a greater-than sign, another space, and finally the name of a file that you wish to create. This file will contain the names of all of the other files. (Using the greater-than sign is known as output redirection.)

dir > filelist.txt

When you issued the DIR command by itself, you probably noticed that it includes not only the name of the file but also details such as the last modified date/time and the file size. If you want those details in the file, then great. There you go. If not, then you can modify the DIR command by adding a /B switch. B Stands for “bare” and it means that only the file names (with filename extensions) will be listed.

dir /b > filelist.txt

Other options you can use with the DIR command include /O:N to sort by name, /O:E to sort by filename extension, /O:-D to sort by date modified (the minus sign means newest first), and /S to recurse into subdirectories,

dir /B /O:E /S > filelist.txt

Here is a comprehensive example of the switches (without the output redirection so that you can see the effects):

DOS DIR

First, DIR alone lists the two files with all of their details. (It also lists two folders “.” and “..”. The single dot refers to the folder itself, and the double dot refers to the parent folder, just FYI.)

Second, DIR /B lists the two files - just their file names, and no mention of the parent folders.

Third, DIR /B /O:E lists the two files again, but this time sorted by filename extension, so that the *.ASC file comes before the *.TXT file.

Comments

  1. This is a great trick, If you want is possible to add this as a preference in context menu when click over a Folder in Windows Explorer:
    - Windows + E -> Tools -> Folder Option -> File Type
    and select (extension: none) File Type: Folder
    click “Advanced”
    and create a new entry, with
    Description: Print file list
    Application: cmd.exe /c dir > “E:\contenuto.txt” “%1″
    sorry for my english I hope you understand, my Windows is not in english.
    When click with right mouse button you have a new option “Print File List”.
    I have a question (If you know), Why if I insert this command nothing is created:
    cmd.exe /c dir > “E:\%1.txt” “%1″
    Thanks

Post a Comment


Your email is never published nor shared. Required fields are marked *



© 2006-2007 Maxim Software Corp.  All rights reserved.