Folder.Files
Accessing DataReturns a table of all files in a folder and its subfolders, including their binary content.
Syntax
Folder.Files(folderPath as text, optional options as nullable record) as tableParameters
| Name | Type | Required | Description |
|---|---|---|---|
folderPath | text | Yes | The full path to the root folder to read (e.g., "C:\Data\Reports" or a UNC path like "\\server\share\folder"). |
options | record | No | An optional record with additional options. |
Return Value
table — A table with one row per file (recursively including subfolders), with columns for Name, Folder Path, Date accessed, Date modified, Date created, Extension, Attributes, and Content.
Remarks
Folder.Files reads a folder and all of its subfolders recursively, returning a flat table with one row per file. Subfolders themselves are not listed as rows — only files are included. This makes it the preferred function when you need to consolidate files that are spread across multiple subdirectories. Use Folder.Contents instead when you only need the immediate contents of a single folder.
Columns returned: Each row includes:
- Name (text) — the file name including extension.
- Folder Path (text) — the full path of the subfolder containing the file (not including the file name). Use this to reconstruct the full path or to filter files from a specific subfolder.
- Date accessed (datetime) — last access timestamp.
- Date modified (datetime) — last modification timestamp.
- Date created (datetime) — creation timestamp.
- Extension (text) — the file extension including the leading dot (e.g., .csv).
- Attributes (record) — file system attributes including Hidden, ReadOnly, System, and Directory.
- Content (binary) — the binary content of the file. Loaded lazily — accessing this column triggers the actual file read.
Authentication: Determined by the Windows credentials of the signed-in user or the service account running the on-premises data gateway. For UNC paths (\\server\share\...), the user or gateway account must have read access to the network share. No Power Query credential configuration is needed for paths accessible under Windows authentication.
Power BI Service and gateway requirements: Folder.Files is not available for direct cloud refresh in Power BI Service. Schedule refresh using an on-premises data gateway installed on a machine with access to the folder path. For files stored in SharePoint or OneDrive for Business, use SharePoint.Files instead, which supports cloud refresh natively.
Performance and lazy evaluation: Content is not read until Power Query accesses it. Always apply row filters (by Extension, Date modified, Name, or Folder Path) before expanding the Content column. Filtering early means Power Query will not open and read files that you do not need, significantly reducing refresh time in large folder trees.
Combine-files pattern: Folder.Files is the engine behind the Power Query UI "Combine Files" experience. The standard M pattern is: get file list → filter to target extension → add a parsed column using the appropriate function → combine the results with Table.Combine.
Examples
Example 1: List all files recursively in a folder tree
```powerquery
Folder.Files("C:\Data\Reports")Example 2: Combine all CSV files across subfolders into one table
```powerquery
let
Source = Folder.Files("C:\Data\Exports"),
CsvFiles = Table.SelectRows(Source, each [Extension] = ".csv"),
Parsed = Table.AddColumn(CsvFiles, "Data", each Csv.Document([Content], [Delimiter=",", Encoding=65001])),
Combined = Table.Combine(Parsed[Data])
in
CombinedExample 3: Combine a specific worksheet from all Excel files in a folder tree
```powerquery
let
Source = Folder.Files("C:\Data\Reports"),
ExcelFiles = Table.SelectRows(Source, each [Extension] = ".xlsx"),
AddedSheets = Table.AddColumn(ExcelFiles, "Workbook", each Excel.Workbook([Content])),
Expanded = Table.ExpandTableColumn(AddedSheets, "Workbook", {"Name", "Data"}),
Sheet1Only = Table.SelectRows(Expanded, each [Name] = "Sheet1"),
Combined = Table.Combine(Sheet1Only[Data])
in
CombinedExample 4: Find the most recently modified file in a folder tree
```powerquery
let
Source = Folder.Files("C:\Data\Reports"),
Sorted = Table.Sort(Source, {{"Date modified", Order.Descending}}),
Latest = Sorted{0}
in
Latest