Getting a List of Folder Contents

In putting together a client's file, Boneita needs to create a document that contains a list of everything in a particular folder—all documents and subfolders. She wonders if there is an easy way to get such a list in Word.

Actually, there are a few ways you can accomplish this task, but none of them are native to Word. Here's an easy way that I use all the time:

  1. Make sure your Word document is open.
  2. Click on the Desktop, outside of Word. (This makes sure that your Word document is not active.)
  3. Press Win+E. Windows immediately opens a File Explorer window.
  4. Using File Explorer, navigate to the folder whose contents you want to list.
  5. Press Ctrl+A. Everything in the folder should now be selected.
  6. While holding down the Shift key, right-click on one of the selected files. Windows displays a Context menu. (See Figure 1.)

Figure 1. Context menu displayed when Shift+right-clicking on a group of files.

What you end up with is the list of files—including full path names—in your document. You can then edit the list in any way desired. For instance, you might want to select what was pasted and use Find and Replace to modify the path to each file, as desired.

If you are looking for a more traditional way of getting the list using the command prompt or a macro, you should consider the WordTip located at this URL:

There are also third-party solutions available, such as Karen's Directory Printer, which was suggested by more than one subscriber:

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (3435) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365.

Author Bio

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. Learn more about Allen.

MORE FROM ALLEN

Hiding Columns Not within a Date Range

Want to automatically hide some columns that don't meet a date criteria that you set? You can't do it automatically, but .

Where Are Word's Settings Stored?

Ever wonder where Word stores all its settings and configuration information? There are only three places where this .

Editing a Document with Many Pages

Working with large or long documents in Word can present some interesting challenges. The most common challenge is that .

Do More in Less Time! Are you ready to harness the full power of Word 2013 to create professional documents? In this comprehensive guide you'll learn the skills and techniques for efficiently building the documents you need for your professional and your personal life. Check out Word 2013 In Depth today!

More WordTips (ribbon)

Using Seek In a Macro

When processing non-document text files in a macro, you have a wide range of commands available for your use. One of .

Saving Documents Using the Same Filename

When working on a document, you most often want to save your edits using the existing name of the document. If Word .

Formatting Text Files with VBA

Got a bunch of text that you've imported from a text file? Need to make it look better? You can take a stab at it with .

Subscribe

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

Comments

Timothy J. McGowan

You can use the Windows Explorer/File Explorer/File Manager trick to find all files in all subfolders as well.

Press Ctrl+F or Ctrl+E to get into the Search box.
Enter a single asterisk (*).
Press the Enter key.

You'll get a listing of all files in that folder and all subfolders.

Press Ctrl+A to select all files (and if it's a large number of items, wait!).
Hold down a Shift key and right-click any highlighted file.
Choose Copy as Path (and you may have to wait again).
Open Word or other destination program.
Paste the listing.

Note: The listing is in no useful order. You'll definitely need to sort the results.

Note too that on my Windows 11 Pro system, the delays in File Explorer were 5 to 10 seconds after choosing to select all files and 20 to 30 seconds to copy as path on a folder of over 21,000 files and subfolders.

This process gives only the folder and file names. If you want file sizes and dates, I would use Andrew's macro below, modifying one line:
Const Switches As String = "/OGNE /TW /S" ' Remove "/S" to exclude subfolders

/O orders the list according to the options following and attached to /O. From the DIR command's help text:
G Group directories first
N By name (alphabetic)
E By extension (alphabetic)
S By size (smallest first)
D By date/time (oldest first)
- (hyphen) Prefix to reverse order

Thus, /OGNE orders the listing by folder (important if you are including the /S switch), then by name, then by file name extension.

/TW gives the date the file was last written. You can instead select for creation date or last-access date:
/TC Creation
/TA Last Access
/TW Last Written

Another third party tool is: Directory ReportIt prints many file attributes

worked great for me. thank you, karmen

Never mind; I got it to work!

I just can't get this to work; when I copy the file path and paste it, this is what I get. "W:\WORKGROUPS\P&E"
Not sure what I am doing wrong!

Here's the way I do it in a macro to create a folder listing in a document via piping the DIR command to a temporary file. This allows using all of the DIR command's options. This is the guts of a larger procedure I use to compare the details of the files (dates, sizes, etc.) in two different directories using Word's CompareDocs feature.

Sub CreateFolderListing()
Const Switches As String = "/OGN /TW /B" ' Add "/S" for subfolders
Dim CommandLine As String
Dim FolderName As String
Dim TempName As String
Dim FSO As New FileSystemObject

FolderName = "c:\"
TempName = FSO.GetSpecialFolder(TemporaryFolder) & "\" & FSO.GetTempName
CommandLine = "cmd.exe /C dir " & Switches & " """ & FolderName & """ > """ & TempName & """"
Call CreateObject("WScript.Shell").Run(CommandLine, 2, True) ' See https://ss64.com/vb/shell.html
Documents.Add.Content.InsertFile filename:=TempName, ConfirmConversions:=False
Kill TempName
End Sub

Getting a List of Folder Contents.
I followed the directions for this task and it worked first time. Great. I have wanted to do that a few times and never knew how.

I want to get macros working in Excel but have had no luck. At one time I was fluent with macros using the ancient Apple II Appleworks program. It was fantastic.

I would also like a VERY SIMPLE flat file database that is popular enough for other people to read. I wish Microsoft had made such a program.

I LOVE THIS TIP! SO EASY! I had a folder of documents for an instructor that he wanted help uploading to his course. After a week, he had not provided what dates to make items available. I used this process and emailed the document to him. He replied in 20 minutes. T

Thank you for such a helpful tip.

A fast and easy way is to open the folder and using a snipping tool make a copy. This will not give you list you can manipulate, but you can print it and have access to a list of your files on paper.

I recommend this third party tool: Directory Report
It can save the contents of your directories to many file formats: txt, csv, xml, directly to MS-Excel, and clipboard
it can get the attributes of: DLL/Exe, AVI, MP3, MSI, WAV and MS-Office properties

Hi Allen
I use Directory Report to get a List of Folder Contents
It can export a directory list directly to MS-Excel
Very customizable

That's a lot of files . . . if I had the need to post a list even much smaller than that and potentially sort on it, I would be inclined to create the list in Excel.

To do that, I would engage a very powerful freebie called ASAP Utilities that has a built in utility to create such a file list (including subfolders) in an Excel file.

(Happily I don't have a need to reference that quantity of files in a Word document).

I was going to give a warning not to try the macro on very large folders such as C:\Windows or C: but Paul has beaten me to it.

For file properties that can be listed, see:
https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/file-object

DateLastModified is probably more useful than DateCreated in the macro, or maybe you need both.

FYI, if you have 58473 files spread across 14354 sub-directories, Ken's macro will give you a Word document with all the files & sub-folders, but it won't create the table, due to Word's limit. Totally neat trick though!

Oh My Goodness! This is a FABULOUS Tip. Thank you so very much. You just saved me bushels of time!

The solution shown will give a list of files in a folder but not its sub folders.

The following macro will produce a list of all files in a folder and its sub-folders. The detail given for each file is the path, the name, the size and the creation date. Other file information could be shown by changing the statement flNames(UBound(flNames)) = …

The results are put into a table in a new document. Word’s Sort can then be used to sort into any order.

' ***** This declaration must be at the top of the module *****
Dim flNames() As String
' ************************************************************
Sub FilesInFolderAndSubFolders()
Dim FileSystem As Object
Dim mydir As String
Dim j As Long
mydir = InputBox("Folder path. For example C:\MyFolder")
ReDim flNames(0)
Set FileSystem = CreateObject("Scripting.FileSystemObject")
DoFolder FileSystem.GetFolder(mydir)
Documents.Add
Selection.TypeText "Path" & vbTab & "File name" & vbTab & _
"Size" & vbTab & "Creation Date" & vbCrLf
For j = 1 To UBound(flNames)
Selection.TypeText flNames(j)
Next j
ActiveDocument.Range.Select
Selection.ConvertToTable Separator:=wdSeparateByTabs, AutoFitBehavior:=wdAutoFitFixed
Selection.Tables(1).Style = "Table Grid"
End Sub

Sub DoFolder(Folder)
Dim SubFolder
Dim aFile
Dim nextDoc As Document
For Each SubFolder In Folder.SubFolders
DoFolder SubFolder
Next SubFolder
For Each aFile In Folder.Files
ReDim Preserve flNames(UBound(flNames) + 1)
flNames(UBound(flNames)) = Folder & vbTab & _
aFile.Name & vbTab & aFile.Size & vbTab & aFile.DateCreated & vbCrLf
Next aFile
End Sub

I too frequently need to list the file contents of a folder in my reports.

I discovered it is fastest to open the target folder in Explorer, organize/display the files you want (e.g. either or without attributes), simply take a screen shot of the file list and paste the graphic into your document.

If the directory path is important to you, just expand the screen shot coverage to include the path shown in the navigation bar too.

David in Mississippi

"Copy as Path" does not show up on my Windows 10 (latest version) context menu. Any help there?

This Site

Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.