Getting a List of Folder Contents

by Allen Wyatt
(last updated March 2, 2019)

9

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.)
  7. Figure 1. Context menu displayed when Shift+right-clicking on a group of files.

  8. Choose the Copy as Path option.
  9. Click in the Word document. (This activates the Word document.)
  10. Make sure the insertion point is where you want the list of file contents added.
  11. Press Ctrl+V to paste the contents of the Clipboard.

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:

https://tips.net/T1466

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

https://www.karenware.com/powertools/karens-directory-printer

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 Office 365.

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

Enlarging Screen Font Size

Sometimes things appearing on the screen are a bit too small to read easily. One possible solution is to adjust the size ...

Discover More

Printing Personalized Copies of a Document

Need to have a series of documents customized for individual users? Mail merge may be overkill, but the macro presented ...

Discover More

Controlling Names of Backup Files

Want to control the name and location of your document backup? Here are some ideas that may help.

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More WordTips (ribbon)

Limits on Path Length in Word

When you organize your hard drive, it is easy to go hog-wild with folders and subfolders. You need to know that how you ...

Discover More

Saving Your Work Automatically

Word can be configured to save your work periodically, on any time schedule you desire. This tip explains this feature ...

Discover More

Searching for a Document

When switching from one version of Word to another it can be confusing to figure out where all the commands and features ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, 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 seven minus 2?

2019-07-02 21:07:01

binaryman

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


2019-03-10 16:25:34

Bin Man

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


2019-03-05 02:46:00

MW

Ken & Paul:

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).


2019-03-04 17:15:53

Ken Endacott

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.


2019-03-04 09:33:03

Paul Hanson

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!


2019-03-03 13:07:02

Dori

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


2019-03-03 08:41:07

Ken Endacott

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


2019-03-02 16:43:00

MW

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.


2019-03-02 15:15:38

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.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, 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.