Creating a List of Files in a Directory

Written by Allen Wyatt (last updated August 5, 2019)

7

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

Using Document Properties to Ensure Consistent References

If you need to refer to the same information over and over in a document, you may be interested in using custom document ...

Discover More

Exporting a Graphics Group

Need to export a graphics group from a chart so that you can use the group in a different program? It's not as easy as ...

Discover More

Notation for Thousands and Millions

When working with very large numbers in a worksheet, you may want the numbers to appear in a shortened notation, with an ...

Discover More
More WindowsTips

Using the DiskPart Utility

The DiskPart utility is a low-level command-line program that lets you manage disks, virtual disks, partitions, and ...

Discover More

Changing the Default Program for a File

Files are opened by programs depending upon the file's type. If you want to change this association so that a different ...

Discover More

Creating a System Repair Disc

Doing a one-time create of a system repair disk can be worth its weight in gold if you find yourself unable to boot your ...

Discover More
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}] (all 7 characters, in the sequence shown) 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 two more than 7?

2019-08-06 08:04:13

Alex B

Thank you Allen, I had previously written this off since most of my files are on network drives. Works a treat, thanks to your clarification.

@Bill
Thank you for you tip as well, that's a neat trick.


2019-08-05 12:50:26

Roy H

So many thanks. While I’m familiar with the command line syntax, I did not know that I could type CMD directly into the Address Bar and land into the intended subdirectory.


2019-08-05 12:00:32

Bill

I used the method you described for years. I recently learned another method. You may wish to try selecting the files in Windows Explorer and then shift + right clicking on one of the selected files. This will bring up the option to "Copy as path". Choosing this option puts the file list into the clip board and you can then paste them into an application.


2019-08-05 10:35:32

Allen

If you map the network (LAN) drive to a drive letter, then this approach will work just fine. I do it all the time, having my network drive mapped to the Z: drive on my system.

-Allen


2019-08-05 10:31:06

Tim Hoogenboom

How about this functionality for files on a LAN?


2019-08-05 08:18:33

Alex B

Sadly does not work on a Network drive :(


2019-08-05 08:07:11

Len Richards

dir /b finds evertyhing ..... perhaps you could possibly add commands to limit to only folders or get a list of the contents of the folder
one example is much of a Windows Tip


Newest Tips