Skip to main content

Power Query: Get a list of file names from folders and sub-folders

Author: Xiaoyang Last Modified: 2022-12-15

In our previous List All File Names From A Folder And Sub-Folders tutorial, you can list all file names from a folder and the sub-folders by some basic methods, such as formula, VBA code, etc. In this article, I will introduce an amazing feature – Power Query, with this feature, you can list all files from a folder and sub-folders dynamically. After getting the filenames, when you delete or insert new files, the file name list will be refreshed automatically.


Get a list of file names from folders and sub-folders with Power Query

To achieve this task by using the Power Query feature, please do with the following steps:

1. In Excel 2016 and Excel 2021, please click Data > New Query > From File > From Folder, see screenshot:

Note: In Excel 2019 and Office 365, you should click Data > Get Data > From File > From Folder, see screenshot:

2. In the opened Browse window, choose the folder contains the files that you want to get the files names from, see screenshot:

3. Then, click Open button, a preview list of documents opens as below screenshot shown:

4. And then, click Transform Data to open the Power Query Editor window, the file attributes are displayed in the window.

5. If you want to get other attributes, such as file size, please click the expand icon in the Attributes column, it will show you a list of additional columns, select the columns that you want to have in the data, and uncheck the rest. Here, I will check Size option, see screenshot:

6. You can also delete the columns that you don’t need. In the Power Query Editor window, select the column you want to delete, right-click the column, and click Remove. See screenshot:

7. After getting the attribute columns you need, please click Close & Load > Close & Load, see screenshot:

8. Now, all the data about the files are loaded into a new worksheet as below screenshot shown:

Tips:

1. If you need the file names changed dynamically when you delete existing files or insert new files into the folder, you just need to click Data > Refresh All, and the file name list will be refreshed to the newest list.

2. With above steps, all files in folder and its sub-folders are listed. If you want to list the file names from the folder only (excluding the sub-folders), you just need to change the Folder.Files to Folder.Contents into the formula bar of the Power Query Editor window, see screenshots:

And now, only the file names and sub-folder names in the specific folder are listed, see screenshot:

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

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

Description


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!
Comments (0)
No ratings yet. Be the first to rate!
There are no comments posted here yet
Leave your comments
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations