Downloads
Power Query MData sourcesBeginner

Folder.Files

Lists the files in a folder, one row per file, with the file's name, extension, dates and its content as binary.

Syntax
Folder.Files(path)

Returns: A table with columns including Content (binary), Name, Extension, Date modified and Folder Path.

What it does

Folder.Files is the start of almost every "combine a folder of files" query. It lists each file in the folder with its details and a Content column holding the file as binary. You filter the list to the files you want, read each one with Excel.Workbook or Csv.Document, and then combine the results. Adding a new file to the folder then updates the query on refresh.

Syntax and arguments

Example

Twelve monthly sales workbooks sit in one folder. The query lists the folder, keeps the .xlsx files, reads the Transactions sheet from each, and stacks them into one table.

let
    Files = Folder.Files("C:\Finance\Monthly"),
    Workbooks = Table.SelectRows(Files, each [Extension] = ".xlsx"),
    Sheets = List.Transform(
        Table.ToRecords(Workbooks),
        (file) => Table.AddColumn(
            Excel.Workbook(file[Content], true){[Item = "Transactions", Kind = "Sheet"]}[Data],
            "Source file", each file[Name])
    ),
    Combined = Table.Combine(Sheets)
in
    Combined

Each file contributes its rows, and a Source file column records which workbook each row came from. That column is what makes a total traceable when a month looks wrong.

Example: a second, different use

Listing the files modified in the last 30 days, using each [Date modified] >= DateTime.LocalNow() - #duration(30, 0, 0, 0), to see what arrived recently.

Things to watch

In business terms

Monthly bank files, branch sales reports, subledger extracts and vendor statements are often delivered one per month to a shared folder. A folder query turns twelve manual openings into one refresh, and the Source file column gives the audit trail.

Related functions

All Power Query M functions · View as Markdown · M basics