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

Printing Summary Information

Word automatically maintains a number of properties for each document you create. As part of those properties you can include ...

Discover More

Importing Many Files Into Excel

Importing a single file is easy. Importing a whole slew of files can be much more of a challenge.

Discover More

Median of Selected Numbers

Need to find a median value in a series of values? It's easy with the MEDIAN function. What isn't as easy is to derive the ...

Discover More
More WindowsTips

Creating a Bootable USB Flash Drive

If your hard disk becomes problematic to the point where you can't even boot from it, you'll be glad you have a bootable USB ...

Discover More

Displaying Details about an Audio File

Audio files have additional attributes that other files don't have. This tip describes how you can display these additional ...

Discover More

Displaying File Extensions

File extensions help both you and Windows understand how to work with a particular file. By default these extensions are not ...

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 8Mpixels. 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 5 + 0?

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.