<!-- https://learnsql.cpetoday.com/functions/m/folder-files -->
# Folder.Files

Language: Power Query M
Category: Data sources
Syntax: Folder.Files(path)
Summary: Lists the files in a folder, one row per file, with the file's name, extension, dates and its content as binary.
Returns: A table with columns including Content (binary), Name, Extension, Date modified and Folder Path.
Level: Beginner
Related: Folder.Contents, File.Contents, Excel.Workbook, Csv.Document, Table.Combine

## 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
- `path`: the folder, as text, such as `"C:\Finance\Bank\2026"`. Use a full path so the query works on any day.

## 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.

```powerquery
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
- The list covers the folder, and it may include files from subfolders. Look at the Folder Path column and filter it if you want only the top level.
- Filter by Extension before reading. Reading a file that is not a workbook produces an error.
- If the monthly files have different headers or column orders, Table.Combine lines up the names but the types may clash. Check each file.
- A file that is open in Excel can be locked. Close the files before the refresh.

## 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.
