Note: The other languages of the website are Google-translated. Back to English

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

If you want to generate a list of file names within a directory in a worksheet, you can process the following ways to get a list of files from a directory in worksheet quickly.


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:

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:

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 psecifc type 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:

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

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 are instered in step 1.

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.

Notes:
  • 1. You should save this workbook as Excel Macro-Enabled Workbook format, if you want the formulas 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*.


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.

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

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 with a powerful feature

The Filename List utility of Kutools for Excel can easily generate a list of files from a directory in a worksheet as below demo shown.    Click to download Kutools for Excel!

doc list all filenames 9

Note:To apply this Filename List, firstly, you should download the Kutools for Excel, and then apply the feature quickly and easily.

After installing Kutools for Excel, please do as this:

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

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

(1.) Click doc-list-files-button 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:

Click to Download Kutools for Excel and free trial 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.

The Best Office Productivity Tools

Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

  • Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • More than 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial. 60-day money back guarantee.
kte tab 201905

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!
officetab bottom
Comments (78)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Dear Sir, Thanks for a very nice informative article on Excel. I was able to fetch the file names from a folder in one column with the help of your module. Now I have a few queries. I will be very grateful to you if you could find some of your precious time to resolve them. Scenario: What I am trying to do and my target: I get realtime data in csv files from my broker terminal. The moment market starts, these csv files (with respective stock names) are created in a particular folder, named data. All these CSV files have three columns TIME PRICE VOLUME. Files names are usually like this: FUTCOM-ALUMINIUM-29NOV2013_MCX113928.csv I am fetching these file names in first column of my RTdata.xlsm. Query 1: When I run your module it asks (searches) for folder. Can I give the full path in module so that it automatically goes that folder instead of searching for it. Where to insert folder path. Query 2: The module fetches full file name. I want it to be trimmed like this: From FUTCOM-ALUMINIUM-29NOV2013_MCX113928.csv to FUTCOM-ALUMINIUM-29NOV2013. Query3: How to further fetch data from three columns TIME PRICE VOLUME from each csv files into my RTdata.xlsm in the row of their respective names. Data from just the last row of each csv files (as they are dynamically changing in real time). I do realise that it is asking for too much. But I humbly request you to kindly guide me. Thanks & Regards. Manu Adam (New Delhi, India)
This comment was minimized by the moderator on the site
Hello Manu Adam, I have a similar query as you query 1. If you have found a solution for that please share the solution or mail me at bharatsharma116@gmail.com. Any help will b really appreciable. thanks in Advance.
This comment was minimized by the moderator on the site
Awesome tutorial!!!! Thanks a lot for this quick solution :-)
This comment was minimized by the moderator on the site
Thank you for posting this! Web browser method was really simple
This comment was minimized by the moderator on the site
very useful information... thanks... Keep it up....
This comment was minimized by the moderator on the site
you guys rock. great add on program. I will be getting the paid version. this was great for working on getting a directory print out of files for a business that had a bad employee deleting files. now to see if it also will print all the files in the directory out for me. at the very least I should be able to use the file list to create a script to print with. thanks a lot.
This comment was minimized by the moderator on the site
I have previously found a mail merge excel utility that would fill columnar info into the form and print it. Problem is I need to create Excel files of the printed info as well. This program creates the files as I would like but does it have the capability to fill into the created files as well?
This comment was minimized by the moderator on the site
Dear All Thanks for VBA code i.e. "Using VBA to list files of a folder in a worksheet" It is realy usefull for generating the list of file name. I am thankfull, if you can provide the code that will select the folder automatically as per define path. Regards Anil M
This comment was minimized by the moderator on the site
Dear All could some one give me way to use file name in macro
This comment was minimized by the moderator on the site
Thank you very much for this useful information.
This comment was minimized by the moderator on the site
Genius in Simplicity..!
This comment was minimized by the moderator on the site
Thanks a lot for this quick solution :-)
This comment was minimized by the moderator on the site
Thank you so very much!!!!! Just what I needed.
This comment was minimized by the moderator on the site
OMG, this is really helpful. I had a folder with 1850 files and i needed to list them as a requirement for Engineering review. one small change might affect milestone submission date. this solution rescued me. thanks a lot.
This comment was minimized by the moderator on the site
Could some one help me to list file names without extensions or a way to remove .pdf or .doc from name of files. Thanks in advance
This comment was minimized by the moderator on the site
Just do Ctrl+H then replace .pdf with nothing You could also do text to columns, delimited, other "."
This comment was minimized by the moderator on the site
This just made my day - Thanks!
This comment was minimized by the moderator on the site
Thanks pete i guess that could be one way by adding a recorded macro but it would be simple if first micro itself generates list of file names without extensions still thanks a lot will try this today
This comment was minimized by the moderator on the site
Four steps is too many for the web browser method? Not really
This comment was minimized by the moderator on the site
awesome method. thanks a ton!! this is amazingly helpful....
This comment was minimized by the moderator on the site
nice.... :-) Is there any macro to auto update the excel from the file directory... when new files are added in the directory
This comment was minimized by the moderator on the site
Thank you! Can't tell you what a lifesaver (and time saver) this was for me!
This comment was minimized by the moderator on the site
Thank you. you saved my time.
There are no comments posted here yet
Load More
Leave your comments
Posting as Guest
×
Rate this post:
0  Characters
Suggested Locations