Creating a List of Files in a Directory

by Allen Wyatt
(last updated December 7, 2015)

4

I've got a directory that contains a ton of graphics files. I was preparing a report that, in one part, needed to list all of the filenames for those files. I didn't want to type all the filenames in from scratch, so I relied on a tried-and-true trick from the DOS days in order to get the filenames into a text file.

  1. Press Win+E to display a Windows Explorer window (Windows 7 and Windows 8) or a File Explorer window (Windows 10).
  2. Using the controls in the window, navigate until you can see the contents of the directory. (In my case, I navigated to the directory that contained all the graphics files.)
  3. In the Address Bar of the window, delete whatever is there, type CMD, and then press Enter. Windows opens a command-prompt window that already points to the directory you displayed in step 2.
  4. Type the following command line and press Enter:
  5. dir /b > myfiles.txt
    
  6. Close the command-prompt window.

That's it. You should note a new file (myfiles.txt) in the directory, and it contains all of the names of the files in the directory. (If you don't see the myfiles.txt at first, press F5 to refresh what is shown in the Explorer window.) In my case, all I did was to copy the filenames and insert them into the report I was preparing—much easier than typing everything!

 This tip (12707) applies to Windows 7, 8, and 10.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Quickly Displaying the Page Setup Dialog Box

The Page Setup dialog box is indispensable in setting up the overall look of your document. You can display the dialog box ...

Discover More

Clean Up Your Macro List

Got a workbook cluttered with all sorts of macros? Delete them and you'll make your workbook easier to manage.

Discover More

Printing via Macro without Messages

When you are printing a document, it is not unusual to see messages (dialog boxes) periodically. When you want the printing ...

Discover More
More WindowsTips

Understanding Storage Spaces

Need to add some addition drive space to your system? Why not consider adding what Microsoft calls a "storage space?" This ...

Discover More

Copying Files to a CD or DVD

You can have virtually unlimited disk space if you're willing to swap discs once in a while. By copying files to a CD or DVD ...

Discover More

Creating a System Repair Disk on a USB Flash Drive

Having a system repair disk is almost as important as doing regular backups. CDs and DVDs, though, tend to get scratched and ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WindowsTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is nine minus 5?

2015-12-09 06:29:03

Shreepad S M Gandhi

Thanks for all the comments and main write-up. I have used printfolders utility available as a freeware. Google for 'printfolders'. They offer a freeware (good functionality) as well as a Prof version too, that many may not need. And it is quite stable too. I have experienced a very good performance of this. Used for 'n' number of purposes for example to print my CD covers (that was 8-10 years back :)) and other file lists etc.


2015-12-07 08:59:25

Ken Sadeckas

and dir/s/b >myfiles.txt will list the directories with their files and their entire path which can help you find them.


2015-12-07 08:58:23

Rudy

I love this tip. Most people now won't know what a directory is until you explain that a directory is a folder.


2015-12-07 08:39:30

Ken Sadeckas

This is a good tip, reminding us of the value of some of the old dos commands. You failed to mention the power of the switches of the dir command, though:

/A Displays files with specified attributes.
attributes D Directories R Read-only files
H Hidden files A Files ready for archiving
S System files I Not content indexed files
L Reparse Points - Prefix meaning not
/B Uses bare format (no heading information or summary).
/C Display the thousand separator in file sizes. This is the
default. Use /-C to disable display of separator.
/D Same as wide but files are list sorted by column.
/L Uses lowercase.
/N New long list format where filenames are on the far right.
/O List by files in sorted order.
sortorder N By name (alphabetic) S By size (smallest first)
E By extension (alphabetic) D By date/time (oldest first)
G Group directories first - Prefix to reverse order
/P Pauses after each screenful of information.
/Q Display the owner of the file.
/R Display alternate data streams of the file.
/S Displays files in specified directory and all subdirectories.
/T Controls which time field displayed or used for sorting timefield.
C Creation
A Last Access
W Last Written
/W Uses wide list format.
/X This displays the short names generated for non-8dot3 file names. The format is that of /N with the
name inserted before the long name. If no short name is present, blanks are displayed in its place.
/4 Displays four-digit years.


Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in WindowsTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.