Skip to main content

How to list all file names from a folder and sub-folders into a worksheet?

Author Tech Support Last modified

If you need to generate a list of file names from a directory into an Excel worksheet, the following methods will help you do this quickly and efficiently. Choose the approach that best suits your needs.


List all file names from a folder into worksheet by using a web browser

If you want to list files in a folder by using the web browser, you should make sure you have one of the web browsers (Firefox, Opera and Google Chrome) installed in your computer. Supposing you need to list files of following folder in worksheet, see screenshot: 

1. Go to copy the path of the folder ("Folder Test") in Explorer. For example, the path of this folder is: "C:\Users\AddinTestWin10\Desktop\Folder Test".

2. Open one of the web browsers (FireFox, Opera and Google Chrome) and paste the folder path in the address bar and press Enter key. See screenshot:

A screenshot of folder path pasted in a browser's address bar

3. Click "Ctrl+A" to select all contents in the web browser and press "Ctrl+C" to copy them.

4. Open Excel and directly paste (using "Ctrl+V" shortcuts to paste) them in a worksheet. See screenshot:

A screenshot of files listed from a folder pasted into an Excel worksheet

Notes:
  • 1. With this method, only the files in the main folder can be displayed, the files in the subdirectory can not be listed.
  • 2. The hyperlinks of the file names are not available.

List all file names from a folder into worksheet by using formula

In Excel, you can also use a formula to get the list of all filenames or specific types of filenames from a folder, please do with following steps:

1. Copy and paste the file path into a cell, and then type  \* after the file path as below screenshot shown:

2. Then, click "Formula" > "Name Manager", see screenshot:

A screenshot showing the Formula Name Manager in Excel

3. In the "Name Manager" dialog box, click "New" button, see screenshot:

A screenshot of New Name dialog box in Excel with the New button highlighted

4. In the popped out "New Name" dialog box, specify a name into the "Name" text box, and then enter the below formula into the "Refers to" text box, see screenshot:

=FILES(Sheet1!$A$1)

Note: In this formula, "Sheet1!$A$1" is the cell of the worksheet contains the file path you instered in step 1.

A screenshot of creating a new name range in Excel

5. And then, click "OK" > "Close" to close the dialogs, and then enter the following formula into a blank cell where you want to list the file names, and drag the fill hanlde down untill blank cells are displayed, now, all file names in the specified folder have been listed as below screenshot shown:

=IFERROR(INDEX(Filenames,ROW(A1)),"")

Note: In this formula, "Filenames" is the range name you are created in step 4, and "A1" is the cell contains the file path.

A screenshot of a list of file names populated in Excel from a folder

Notes:
  • 1. You should save this workbook as "Excel Macro-Enabled Workbook" format, if you want the formulas to work well after the file is closed and reopened.
  • 2. If you want to list all files with a specific extension, such as list all docx file names, in this case, you just need to use *docx* instead of *, similarly, for xlsx files, please use *xlsx*.

    An animation showing filtering for specific file types in Excel


List all file names from a folder into worksheet by using VBA code

Using the following VBA to list files in a folder in a worksheet:

1. Open a worksheet, and click to select a cell where you want to put the filenames.

2. Hold down the "ALT + F11" keys in Excel, and it opens the "Microsoft Visual Basic for Applications" window.

3. Click "Insert" > "Module", and paste the following code in the "Module" Window.

VBA code: List all file names from a folder into a worksheet

Sub listfiles()
'Updateby Extendoffice
    Dim xFSO As Object
    Dim xFolder As Object
    Dim xFile As Object
    Dim xFiDialog As FileDialog
    Dim xPath As String
    Dim I As Integer
    Set xFiDialog = Application.FileDialog(msoFileDialogFolderPicker)
    If xFiDialog.Show = -1 Then
        xPath = xFiDialog.SelectedItems(1)
    End If
    Set xFiDialog = Nothing
    If xPath = "" Then Exit Sub
    Set xFSO = CreateObject("Scripting.FileSystemObject")
    Set xFolder = xFSO.GetFolder(xPath)
    For Each xFile In xFolder.Files
        I = I + 1
        ActiveSheet.Hyperlinks.Add Cells(I, 1), xFile.Path, , , xFile.Name
    Next
End Sub

4. Then press F5 key to run the code, a new window "Browse" will be displayed. Select the folder you would like to be listed the filenames.

A screenshot of the file browse window in VBA

5. Then click OK, the files in the specific folder have been listed into the worksheet with hyperlinks. See screenshot:

A screenshot of file names listed with hyperlinks in Excel

Note:Only the file names in the main folder can be listed.

List all file names from a folder and sub-folders into a worksheet by using Kutools

The "Filename List" utility of "Kutools for Excel" can easily generate a list of files from a directory in a worksheet.

Kutools for Excel offers over 300 advanced features to streamline complex tasks, boosting creativity and efficiency. Itegarate with AI capabilities, Kutools automates tasks with precision, making data management effortless. Detailed information of Kutools for Excel...         Free trial...

1. Open Excel, Click "Kutools Plus" > "Import / Export" > "Filename List…, "see screenshot:

2. In the "Filename List" dialog box, do the following operations:

A screenshot of Filename List dialog box options

(1) Click A screenshot of the folder selection button in the Filename List dialog box button to specify the folder which contains the files you want to list;

(2) Check the "Include files in subdirections" option to list all file names in subfolders or check the "Include hidden files and folders" option to list all names of hidden files as well as file names in hidden folders;

(3) Specify the file type that you want to list under the "Files type" section;

(4) Select one file size unit you want to display from the "File size unit" section you need.

(5) Check the "Create hyperlinks" option as you need.

3. Click OK. It will generate a list of files in the directory or subdirectory in a new worksheet. See screenshot:

A screenshot of a complete file name list generated using Kutools

Kutools for Excel - Supercharge Excel with over 300 essential tools. Enjoy permanently free AI features! Get It Now


More relative articles:

  • Create A List Of All Worksheet Names From A Workbook
  • Supposing, you have a workbook with multiple worksheets, now you want to list all of the sheet names in current workbook, is there any quick method for creating a list of theses sheet names in Excel without typing them one by one? This tutorial is giving instructions on how to list worksheet names in Excel.
  • Copy Or Move Files From One Folder To Another Based On A List
  • If you have a list of file names in a column in a worksheet, and the files locate in a folder in your computor. But, now, you need to move or copy these files which names are listed into the worksheet from their original folder to another one as following screenshot shown. How could you finish this task as quickly as you can in Excel?
  • Navigate Between Worksheets By Using Drop Down List 
  • Supposing, you have a workbook which contains multiple worksheets, now, you need to create a drop down list or combo box which lists all sheet names and when you select one sheet name from the drop down list, it will jump to that sheet immediately. This article, I will introduce how to navigate between worksheets by using a drop down list in Excel.

Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more
Use Kutools in your preferred language – supports English, Spanish, German, French, Chinese, and 40+ others!

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!