This post may contain affiliate links. Please read my disclosure for more info.

Power Query – List All the Files in a Folder & File Attributes

Power Query - Files in a FolderPower Query - Files in a Folder

In the last post, we saw how to import all the files from a folder, which is a fantastic time-saving technique.  While focusing on this aspect, we skipped over another useful part of Power Query; which is being able to obtain a list of all the files in a folder, and sub-folders, along with the file attributes.

I have previously written posts about how to list all the files in a folder using VBA and also using a legacy Excel 4 function.  These posts still receive lots of search traffic from Google, so  I know this is an area which users are interested in.  However, in Power Query, we now have the easiest method of all.

List all the files in a folder (and sub-folders)

In Excel, click Data -> Get Data-> From File -> From Folder.

Import files from folder

In the Folder window click Browse…, navigate to the folder then click OK.

Folder window - Browse

When the list of documents opens click Transform Data.

List of Files - Transform Data

The Power Query Editor opens and shows some useful attributes:

  • Name
  • Extension
  • Data accessed
  • Date modified
  • Date created
  • Folder Path

Move the Name column to the end, then select the Name and Folder Path columns, click Add Column -> Merge Columns.

Add Column - Merge Columns

On the Merge Columns window, choose no separator and click OK.

Merge Columns Window

A new column is created with the complete file path.  Make the following transformations:

  • Rename the new column.
  • Remove all except the new column.

The Preview window shows a list of all the files and folders.

List of files - Preview Window

Click Home -> Close and Load to push the data into Excel.

How easy was that!

File attributes

In the section above, we saw some file attributes, mostly based on dates, but this is just the start.  The Attributes column in the Preview Window provides access to lots of other information.

Expand Attribute button

Click on the expand icon in the header of the Attributes column, then click OK to see the file attributes.  I’m not going to lie… I have no idea what some of these attributes are, but others very useful, such as:

  • Kind – the file type
  • Size – the file size
  • Read-only – whether the file is currently set to Read-Only
  • Hidden – whether the file is visible

Imagine that your disk space is getting low.  Using this method, you can quickly identify the largest file sizes, or the files which have not been opened recently, or duplicate file names.  Once you have this list, you can decide what to keep and what to delete.

Worksheet attributes

Attributes don’t finish at the file level either.  Follow the steps above to navigate a folder containing Excel files.  Filter to include only the Excel files you’re interested in.  Your Preview Window might look like this.

Show all Excel Files

Click Add Column -> Custom Column.

In the Custom Column window to enter the following settings:

Column Name: ExcelFile

Custom column formula:

=Excel.Workbook([Content])

Click OK.

Custom Column - Content

Click the Expand icon on the ExcelFile column to drill into each file.

Expand icon Excel file

The attributes here provide:

  • Worksheet name
  • Kind – worksheet or table
  • Hidden – whether the worksheet is hidden

In conclusion

There you have it.  A useful little trick to get information about files.  Even today, I used this technique to check whether an automated process exported the same files as last month.  Now I can click refresh and this check is completed in seconds.

Series Contents

  1. Introduction
  2. Import Data
  3. Data Refresh
  4. Edit Queries
  5. Close & Load Options
  6. Using Parameters
  7. Basic Transformations
  8. Combine / Append Queries
  9. Import All Files in a Folder
  10. List All the Files in a Folder and File Attributes
  11. Import Data from the Current Workbook
  12. Import Data from the Web
  13. Unpivot Data
  14. Unstacking Data in a Column
  15. Lookup Values using Merge
  16. Change the Source Data Location
  17. Formulas
  18. If Statements for Conditional Logic

Leave a Reply

Your email address will not be published. Required fields are marked *