Watch Video – Get a List of File Names from Folders & Sub-folders
Some time ago I wrote an Excel Tutorial about getting a list of file names from a folder in Excel.
In that tutorial, I showed various ways to get the list of file names from a folder (using the FILE function and VBA).
However, the limitation of that method is that it can only get the file names from a folder, and not from the sub-folders within the main folder.
But you can do this using Power Query (‘Get & Transform’ if you’re using Excel 2016 or later versions).
Where to find Power Query
If you’re using Excel 2016, you don’t need to do anything extra. You will find all the Power Query options in the Get & Transform category in the Data tab.
Note that Power Query and Get & Transform refer to the same thing.
For Excel 2010/2013, you need to install the Power Query add-in to use it (steps described below).
- Click here to download the Power Query add-in. Make sure you are downloading 32-bit if your Excel is 32-bit and 64 bit if your Excel is 64 bit.
- Install the Power Query add-in.
- Open Excel. If you see a Power Query tab, skip the remaining steps. If not, move to the next step.
- Go to File and click on Options.
- In the ‘Excel Options’ dialog box, click on Add-in in the left pane.
- From the Manage drop-down, select COM Add-ins, and click on Go.
- In the list of available add-ins, select Power Query and click OK.
- Close the Excel Application and restart Excel.
The above steps would install and activate the Power Query for your Excel.
Get a List of File Names from Folders & Sub-folders
Now let’s see how to get a list of all the files names from a folder and sub-folders within it.
Here are the steps to get a list of all the file names from a folder:
- Go to the Data tab.
- In the Get & Transform group, click on New Query.
- Hover the cursor on the ‘From File’ option and click on ‘From Folder’.
- In the Folder dialog box, enter the folder path, or use the browse button to locate it.
- Click OK.
- In the dialog box that opens, you’ll see the names of all the files along with other metadata.
- Click on the Load button.
The above steps would load all the data about the files in your Excel worksheet.
Once you have the data in Excel, you can edit it if needed.
With the data that I have in Excel, I can do the following:
- Filter the file0 names based on extension (file type) – it’s in column B.
- Filter the file names based on the folder name – it’s in column F.
Editing the Columns Data in Power Query
Before loading your data into Excel, you can also edit the data in Power Query.
For example, you can delete some columns or get some more metadata for each file.
Here are the steps to get additional metadata columns in Power Query editor:
- Go to the Data tab.
- In the Get & Transform group, click on New Query.
- Hover the cursor on the ‘From File’ option and click on ‘From Folder’.
- In the Folder dialog box, enter the folder path, or use the browse button to locate it.
- Click OK.
- In the dialog box that opens, click on ‘Edit’.
- In the Power Query editor, click on the expand icon in the ‘Attributes’ column. It will show you a list of the additional columns you can get for the files (such as file size or read-only or hidden). Select the columns that you want to have in the data (and uncheck the rest).
- Click OK.
- Click on ‘Load’.
This will load the data in the Excel with the selected additional columns.
You can also delete columns if you don’t need it. To do this, in the Power Query editor, select the column you want to delete, right-click, and click on Remove.
You May Also Like the Following Excel Tutorials:
- Get a List of All the Comments in a Worksheet in Excel.
- How to Combine Multiple Excel Files into One Excel Workbook.
- How to Combine Data from Multiple Workbooks into One Excel Table (using Power Query).
- Combine Data From Multiple Worksheets into a Single Worksheet in Excel.
- Merge Tables in Excel Using Power Query.
11 thoughts on “Get a List of File Names from Folders & Sub-folders (using Power Query)”
It’s possible to get the file’s name from the subfolders using FSO as well, you just need to know how to implement inheritance
Elton Senne
Amazing, saved a lot of a time. Thanks for sharing the info.
if I have files in folder and subfolder more the 100,000 file how it will work
THANK YOU SIR, YOU DID GREAT JOB THANKS A LOT
Great tutorial. If I have other metadata like “tags”, “author” on files, how can show add those columns?
Really useful, thank you
Really it is a good site for excel learning .
Thank you Sumit. Very good tip using Power Query.
Can we get power query in excel 2007?
Unfortunately, Power Query is not available for Excel 2007
Thanks.