Folder.Contents

Accessing Data

Returns a table of files and subfolders in the specified local or network folder path.

Examples on this page use shared sample tables. View them to understand the input data before reading the examples below.

Syntax

Folder.Contents(folderPath as text, optional options as nullable record) as table

Parameters

NameTypeRequiredDescription
folderPathtextYesThe full path to the folder to read (e.g., "C:\Data\Reports" or a UNC path like "\\server\share\folder").
optionsrecordNoAn optional record with options. Supports IncludeSubFolders (logical, defaults to false) to include items from subfolders recursively.

Return Value

tableA table with one row per file or subfolder, including columns for Name, Folder Path, Date accessed, Date modified, Date created, Extension, Attributes, and Content.

Remarks

Folder.Contents reads a local or network folder and returns a table with one row per file or subfolder found at that path. Unlike Folder.Files, it does not recurse into subfolders by default — it returns only the immediate children (files and one level of subdirectories). To include all files from subfolders recursively, pass [IncludeSubFolders = true] in the options record, or use Folder.Files instead.

Columns returned: Each row in the result includes: - Name (text) — the file or folder name including extension. - Folder Path (text) — the full path of the containing folder (without the file name). - 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., .xlsx). Empty string for folders. - Attributes (record) — file system metadata attributes including Hidden, ReadOnly, System, and Directory. - Content (binary) — the binary content of the file. null for subfolders.

Authentication: Determined by the Windows credentials of the currently signed-in user or the service account running the on-premises data gateway. No credential configuration is required in Power Query for local paths. UNC paths (e.g., \\server\share\folder) require the user or gateway account to have read access to the network share.

Power BI Service and gateway requirements: Folder.Contents is not available for direct cloud refresh in Power BI Service. An on-premises data gateway installed on a machine with access to the folder path is required for scheduled refresh. SharePoint document libraries should use SharePoint.Files instead.

Query folding: Not supported. All filtering occurs in Power Query after the directory listing is fetched. For best performance, apply Table.SelectRows on Extension, Date modified, or Name before accessing the Content column, as Content is loaded lazily and does not trigger a file read until accessed.

Combining files: The standard pattern is: list files → filter by extension or name → expand Content using a parsing function. Pass each Content binary to Csv.Document, Excel.Workbook, Json.Document, or Pdf.Tables depending on the file type.

Examples

Example 1: List all files and subfolders in a directory

```powerquery

Folder.Contents("C:\Data\Reports")

Example 2: Filter to only CSV files in the folder

```powerquery

let
    Source = Folder.Contents("C:\Data\Reports"),
    CsvFiles = Table.SelectRows(Source, each [Extension] = ".csv")
in
    CsvFiles

Example 3: Combine all CSV files in the folder into one table

```powerquery

let
    Source = Folder.Contents("C:\Data\Reports"),
    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
    Combined

Example 4: List files modified after a specific date

```powerquery

let
    Source = Folder.Contents("C:\Data\Reports"),
    Recent = Table.SelectRows(Source, each [Date modified] > #datetime(2024, 1, 1, 0, 0, 0))
in
    Recent

Compatibility

Power BI Desktop Power BI Service Excel Desktop Excel Online Dataflows Fabric Notebooks