Folder.Files Function (Power Query M)

Folder.Files returns a table listing every file in a folder and all of its subfolders. Available in Excel (Power Query), Power BI Desktop, and Power BI Service.

If you want to pull a whole folder of files into Power Query so you can filter, combine, or grab the latest one, this is the function you start with.

You get one row per file, and each row even includes the file content as a binary you can expand later.

Syntax of Folder.Files Function

Folder.Files(path as text, optional options as nullable record) as table

where

  • path (required, text). The absolute path to the folder you want to read, for example "C:\Sales\Monthly". It must be a valid full path that exists.
  • options (optional, nullable record). Reserved by Microsoft for internal use. In normal queries you leave it out.

Returns: a table with one row per file and the columns Content, Name, Extension, Date accessed, Date modified, Date created, Attributes, and Folder Path.

The Content column holds the file as a binary, and Folder Path tells you which subfolder each file came from.

Example 1: List every file in a folder and its subfolders

Point Folder.Files at a folder and it returns the full file table.

let
Source = Folder.Files("C:\Sales\Monthly")
in
Source

The result has one row for every file, not just in C:\Sales\Monthly but in all of its subfolders too, because Folder.Files always recurses.

Each row carries the same eight columns: Content (the file as a binary), Name, Extension, Date accessed, Date modified, Date created, Attributes, and Folder Path.

The Folder Path column is what lets you tell files in nested subfolders apart from files in the top folder.

Example 2: Keep only the Excel files

Use Table.SelectRows to filter on the Extension column and drop everything that is not an .xlsx file.

let
Source = Folder.Files("C:\Sales\Monthly"),
ExcelOnly = Table.SelectRows(Source, each [Extension] = ".xlsx")
in
ExcelOnly

The result keeps only the rows where Extension equals ".xlsx", with the same eight columns as before.

Note the leading dot and the lowercase letters in ".xlsx". Folder.Files reports extensions in lowercase with the dot included, and the comparison is case-sensitive, so ".XLSX" would match nothing.

Example 3: Keep just the useful columns

The Content binary is bulky and the timestamps are often noise. Use Table.SelectColumns to keep only the columns you actually need.

let
Source = Folder.Files("C:\Sales\Monthly"),
ExcelOnly = Table.SelectRows(Source, each [Extension] = ".xlsx"),
Trimmed = Table.SelectColumns(ExcelOnly, {"Name","Folder Path","Date modified"})
in
Trimmed

The result has just three columns, Name, Folder Path, and Date modified, with one row per Excel file.

Dropping the Content column here is only cosmetic. The files are not read until you expand that binary, so trimming it away does not save you the download.

Example 4: Grab the most recent file

A common need is to load only the newest file in a folder. Sort by Date modified descending, then keep the first row with Table.FirstN.

let
Source = Folder.Files("C:\Sales\Monthly"),
ExcelOnly = Table.SelectRows(Source, each [Extension] = ".xlsx"),
Sorted = Table.Sort(ExcelOnly, {{"Date modified",Order.Descending}}),
Latest = Table.FirstN(Sorted, 1)
in
Latest

The result is a single-row table holding the Excel file with the latest Date modified value, still with all eight columns.

From here you would expand its Content binary with something like Excel.Workbook to read the data out of that one file. This is the standard “get data from the latest file in a folder” pattern.

Things to keep in mind with Folder.Files

  • It always recurses into every subfolder. There is no flat-only option. To limit the scope, either filter the [Folder Path] column, or switch to Folder.Contents and navigate the immediate items yourself.
  • Content holds file binaries, not data. To read what is inside, expand that column with the right parser, for example Excel.Workbook for workbooks or Csv.Document for CSV files, then combine the results. This is the same kind of raw binary you get back from a download before you parse it.
  • Extension matching is case-sensitive and includes the dot. Folder.Files returns extensions lowercased, so filter with ".xlsx", not "xlsx" or ".XLSX".
  • The path must exist and be reachable. A missing folder, a typo, or a network path you cannot access throws an error instead of returning an empty table.
  • The date columns are machine-local and change. Date accessed, Date modified, and Date created come from the file system, so they shift over time and differ per machine. Do not rely on them as stable keys.
  • Folder.Files vs Folder.Contents. Folder.Files gives you a flat, recursive list of files only. Folder.Contents gives you the immediate items in one folder, including subfolders, which you then drill into.

Performance and query folding

Enumerating a folder never folds, so the work always happens locally. Over a large tree, and especially a network share, walking every subfolder can be slow because Folder.Files recurses through all of them.

Filter early on [Folder Path] or [Extension] to cut the row count, and leave the Content binaries unexpanded until you actually need the file data, since expanding them is what triggers the real reads.

Common questions about Folder.Files

How do I combine all the files in a folder into one table?

Filter down to the files you want, then expand each file’s Content binary with the matching parser, such as Excel.Workbook or Csv.Document, and stack the results with Table.Combine. The Folder Path column is handy for keeping track of where each row came from.

Should I use Folder.Files or Folder.Contents?

Use Folder.Files when you want every file in a folder tree as one flat list. Use Folder.Contents when you want the immediate contents of a single folder, including its subfolders as items you choose to drill into.

List of All Power Query Functions

Related Power Query Functions / Articles:

I am a huge fan of Microsoft Excel and love sharing my knowledge through articles and tutorials. I work as a business analyst and use Microsoft Excel extensively in my daily tasks. My aim is to help you unleash the full potential of Excel and become a data-slaying wizard yourself.