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

Controlling the Bold Text Attribute

When processing a document in a macro, you may need to make some of your text bold. It's easy to do using the Bold attribute, ...

Discover More

ExcelTips Ribbon 2015 Archive (Table of Contents)

ExcelTips is a weekly newsletter that provides tips on how to effectively use Microsoft's best-selling spreadsheet ...

Discover More

Printing All or Nothing

Want to make sure that when you worksheet is printed that everything in the workbook is really printed? You can accomplish ...

Discover More
More WindowsTips

Restoring from a Backup

Being able to restore from a backup is just as important as making the backup in the first place. This tip tells you how to ...

Discover More

Encrypting a File Folder

Want to make the data stored on your system more secure? Think about enabling the built-in encryption capabilities of Windows ...

Discover More

Rebuilding the Search Index

There may be times when you want to reset the search index and rebuild it from scratch. This tip tells you how.

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. Maximum image size is 6Mpixels. 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 9 - 2?

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.