The Folder.Files function in Power Query gives you a list of every file in a folder, including the files inside its subfolders. You get one row per file, with its name, extension, dates, folder path, and the file’s content.
That list is where most “combine all files in a folder” queries start. Once you have it, you can filter it down to the files you want, check their size or date, or read every file into one table.
In this article, I’ll show you how Folder.Files works with practical examples, from listing files to combining a folder of CSV files.
Follow along with the example file
Folder.Files Function Examples.zip
Folder.Files Function Syntax
Folder.Files(path as text, optional options as nullable record) as table
- path – the full path of the folder you want to list, like
"C:\Reports\Sales". It has to be the full path of the folder, not a relative one. - options (optional) – Microsoft says this argument is currently meant for internal use only, so you can leave it out.
What it returns: A table with one row for each file in the folder and in all its subfolders. It has eight columns: Content, Name, Extension, Date accessed, Date modified, Date created, Attributes, and Folder Path.
The Content column holds each file’s data as a binary (you read it with a function like Csv.Document or Excel.Workbook). The Attributes column holds a record with more details about the file, such as its size.
The Folder.Files function works in Power Query in Excel and Power BI Desktop.
When to Use the Folder.Files Function
Use this function when you need to:
- Get a list of all the file names in a folder and its subfolders
- Keep only one type of file, like CSV or Excel files
- Find the largest file or the most recently changed file in a folder
- Pull information from the folder names, like which shop or region a file belongs to
- Combine every file in a folder into one table that updates when you add a file
How the Example Files Work
Folder.Files reads a real folder on your computer, so this download is a zip, and the example paths are for Excel on Windows. It has the examples workbook with all the queries and a Shop Sales folder with the files the queries list.
The Shop Sales folder holds the monthly sales exports of an ice cream business with two shops. There’s a Notes.txt file directly inside it, plus three subfolders: Downtown and Harbor (three monthly CSV files each) and Archive (one older CSV file).
The queries don’t type the folder path into every formula. Instead, they use a parameter called SalesFolder that holds the path to the Shop Sales folder.
If you unzip the download into C:\Users\Public\Documents, you get a folder called C:\Users\Public\Documents\Folder.Files, and the queries work as they are.
When you extract, set the destination to C:\Users\Public\Documents itself. Windows usually suggests a new folder named after the zip, which puts Folder.Files one level deeper, and then the queries can’t find the files.
If that happens, move the Folder.Files folder up into C:\Users\Public\Documents, or change the parameter as shown below.
If you save the files somewhere else, open the Power Query Editor, go to Home > Manage Parameters, and change SalesFolder to the path of your Shop Sales folder. The Start Here sheet in the examples workbook lists these steps too.
In your own file, you can skip the parameter and type the path straight into the formula, like Folder.Files("C:\Reports\Sales"). A parameter just makes the path easy to change later.
Example 1: List All Files in a Folder
Let’s start with the basic use. You have a folder with files in it (some of them in subfolders), and you want to see all of them in Power Query.
Do this in the examples workbook, since that’s where the SalesFolder parameter lives (each example is also there as a ready-made query under Data > Queries & Connections). In your own workbook, put the quoted folder path in place of SalesFolder.
Go to Data > Get Data > From Other Sources > Blank Query. In the Power Query Editor, open the Advanced Editor (Home > Advanced Editor) and use this code:
let
Source = Folder.Files(SalesFolder)
in
Source
Result: A table with eight rows, one for each file, and eight columns

Here, Folder.Files lists every file in the Shop Sales folder. Notes.txt comes first because it sits directly in the folder, and then you get the files from the Archive, Downtown, and Harbor subfolders.
The Folder Path column tells you which folder each file is in. It always ends with a backslash, like C:\Users\Public\Documents\Folder.Files\Shop Sales\Harbor\.
Two of the date columns will show different values on your computer. Date created and Date accessed show when the files landed on your PC (when you unzipped them), while Date modified keeps the original date from the zip.
Note that the result has only files, not folders. The Folder.Contents function works differently: it lists only the top level of the folder, with one row for each file and each subfolder there.
Example 2: Get Just the File Names, Types, and Folders
Most of the time, you don’t need all eight columns. Here’s how to get a clean list of file names with their extension and folder.
Create a new blank query (Data > Get Data > From Other Sources > Blank Query), open the Advanced Editor, and use this code:
let
Source = Folder.Files(SalesFolder),
#"Kept Columns" = Table.SelectColumns(Source,{"Name","Extension","Folder Path"})
in
#"Kept Columns"
Result: A table with three columns (Name, Extension, Folder Path) and one row for each of the eight files

Here, Folder.Files lists the files, and the Table.SelectColumns function keeps only the three columns we want. This is a quick way to list the file names in a folder and load them to a sheet.
Notice that the same file name shows up more than once. There’s a 2026-04.csv in Downtown and another one in Harbor, so the Folder Path column is what tells them apart.
Example 3: Get Only the CSV Files
This next one comes up all the time. You want to work with only one type of file, and the folder has other files in it too.
Here, I want only the CSV files, so Notes.txt should drop out. Create a new blank query and use this code:
let
Source = Folder.Files(SalesFolder),
#"CSV Files" = Table.SelectRows(Source,each Text.Lower([Extension])=".csv"),
#"Kept Columns" = Table.SelectColumns(#"CSV Files",{"Name","Folder Path"})
in
#"Kept Columns"
Result: Seven CSV files, including 2026-06.CSV in the Downtown folder

Here, the Table.SelectRows function keeps only the rows where the extension is .csv, and the Table.SelectColumns function keeps the Name and Folder Path columns.
The Extension column keeps the same case as the file name. The Downtown shop’s June file was saved as 2026-06.CSV, so its extension is .CSV, in capital letters.
Important: Power Query text comparisons are case-sensitive, so a filter like [Extension]=".csv" silently skips 2026-06.CSV. Wrapping the column in the Text.Lower function turns every extension into lowercase first, so the filter catches all of them.
If you filter for Excel files this way, also leave out names that start with ~$. Excel creates one of those temporary files next to any workbook that’s open, and it has the same .xlsx extension.
To do that, add and not Text.StartsWith([Name],"~$") at the end of the condition in the Table.SelectRows step.
Example 4: Leave Out the Files in One Subfolder
Since Folder.Files also picks up the files in every subfolder, you’ll sometimes get files you don’t want. Here’s how to leave out one subfolder.
The Archive folder has an old March file that I don’t want in the list. Create a new blank query and use this code:
let
Source = Folder.Files(SalesFolder),
#"Current Files" = Table.SelectRows(Source,each not Text.Contains([Folder Path],"\Archive\",Comparer.OrdinalIgnoreCase)),
#"Kept Columns" = Table.SelectColumns(#"Current Files",{"Name","Folder Path"})
in
#"Kept Columns"
Result: Seven files, everything except 2026-03.csv in the Archive folder

Here, the Text.Contains function checks whether the folder path has \Archive\ in it, and not keeps the rows where it doesn’t. Notes.txt and the six shop files stay.
The Comparer.OrdinalIgnoreCase part makes the check ignore case, so a folder named archive or ARCHIVE is left out too. It’s the same idea as Text.Lower in Example 3.
The check looks at the whole folder path. So if the folder you point Folder.Files at sits inside a folder that’s also called Archive, every file gets left out, and you’d need a more specific text to match.
I’ve put a backslash on both sides of Archive, so it only matches a folder with exactly that name. Without them, a folder like Archive Old or a path such as \Archived Reports\ would match too.
Example 5: Get the Shop Name from the Folder Name
The folder names here carry useful information. Each shop has its own subfolder, so the folder name tells you which shop a file belongs to.
I want the current CSV files with a Shop column that holds the name of the folder each file is in. Create a new blank query and use this code:
let
Source = Folder.Files(SalesFolder),
#"CSV Files" = Table.SelectRows(Source,each Text.Lower([Extension])=".csv" and not Text.Contains([Folder Path],"\Archive\",Comparer.OrdinalIgnoreCase)),
#"Added Shop" = Table.AddColumn(#"CSV Files","Shop",each Text.AfterDelimiter(Text.TrimEnd([Folder Path],"\"),"\",{0,RelativePosition.FromEnd}),type text),
#"Kept Columns" = Table.SelectColumns(#"Added Shop",{"Shop","Name"})
in
#"Kept Columns"
Result: Six files, three with Downtown and three with Harbor in the Shop column

Here, the filter in the CSV Files step combines the two conditions from Examples 3 and 4, so you get only the CSV files that aren’t in the Archive folder.
Folder Path ends with a backslash, so there’s nothing after the last backslash until you remove it. That’s what the Text.TrimEnd function does here.
Then the Text.AfterDelimiter function takes everything after the last backslash (the {0,RelativePosition.FromEnd} part means “count from the end”), which is the folder name.
This works no matter how deep the folder is, because it always takes the last folder in the path. So it keeps working if you move the Shop Sales folder somewhere else.
Example 6: Get the Size of Each File
Folder.Files doesn’t have a Size column, but the size is in there. It sits inside the Attributes column.
I want each file’s size in bytes, with the largest file at the top. Create a new blank query and use this code:
let
Source = Folder.Files(SalesFolder),
#"Added Size" = Table.AddColumn(Source,"Size",each [Attributes][Size],Int64.Type),
#"Kept Columns" = Table.SelectColumns(#"Added Size",{"Name","Folder Path","Size"}),
#"Sorted Rows" = Table.Sort(#"Kept Columns",{{"Size",Order.Descending}})
in
#"Sorted Rows"
Result: The eight files sorted by size, starting with Notes.txt (126 bytes) and ending with 2026-06.CSV (88 bytes)

Here, each row’s Attributes value is a record, and [Attributes][Size] picks the Size field from it. The Table.Sort function then puts the largest file first.
The Attributes record has 20 fields in all. Besides Size, you get things like Hidden and ReadOnly (TRUE or FALSE), and Content Type.
To see all of them, click the white space next to any Record value in the Attributes column, and a preview opens at the bottom. Clicking the word Record itself drills into that one record and adds a step, which you’d then delete.
To show the size in KB, divide by 1024 and change the type to a decimal number, like Table.AddColumn(Source,"Size",each [Attributes][Size]/1024,type number). Int64.Type is for whole numbers, and KB sizes have decimals.
You can also get the Size column without writing the step. Click the expand icon in the Attributes column header, keep only Size, and click OK.
Example 7: Find the Most Recently Modified File
Here’s another common one. You get a new export every month, and you want the latest file without checking the dates yourself.
I want the one file that was changed last, from anywhere in the Shop Sales folder. Create a new blank query and use this code:
let
Source = Folder.Files(SalesFolder),
#"Latest File" = Table.MaxN(Source,"Date modified",1),
#"Kept Columns" = Table.SelectColumns(#"Latest File",{"Name","Folder Path","Date modified"})
in
#"Kept Columns"
Result: One row, 2026-06.csv in the Harbor folder, modified on 7/1/2026 4:40:00 PM

Here, the Table.MaxN function looks at the Date modified column and keeps the one row with the latest date. Both June files were saved on July 1, but the Harbor file was saved later that day, so it wins.
I’ve used Table.MaxN instead of the Table.Max function because Table.MaxN returns a table, while Table.Max returns a single record. A table works with the Table.SelectColumns step after it and loads to a sheet like any other query.
Change the 1 to a 3, and you get the three newest files.
The date you see depends on your regional settings, so a UK computer shows 01/07/2026 16:40:00 for the same date. Unzipping the download keeps each file’s modified date, so you should get this same file.
If you open and save one of the sample files, its Date modified changes to that moment, so that file becomes the newest one instead.
Example 8: Combine All the CSV Files into One Table
This is the reason most people use Folder.Files. You want the data from every file in the folder stacked in one table, and you want new files to show up when you refresh.
I want the rows from the six current CSV files in one table, with a Shop column so I know where each sale came from. Create a new blank query and use this code:
let
Source = Folder.Files(SalesFolder),
#"CSV Files" = Table.SelectRows(Source,each Text.Lower([Extension])=".csv" and not Text.Contains([Folder Path],"\Archive\",Comparer.OrdinalIgnoreCase)),
#"Added Shop" = Table.AddColumn(#"CSV Files","Shop",each Text.AfterDelimiter(Text.TrimEnd([Folder Path],"\"),"\",{0,RelativePosition.FromEnd})),
#"Added Data" = Table.AddColumn(#"Added Shop","Data",each Table.PromoteHeaders(Csv.Document([Content]))),
#"Kept Columns" = Table.SelectColumns(#"Added Data",{"Shop","Data"}),
#"Expanded Data" = Table.ExpandTableColumn(#"Kept Columns","Data",{"Date","Flavor","Scoops","Amount"}),
#"Changed Type" = Table.TransformColumnTypes(#"Expanded Data",{{"Shop",type text},{"Date",type date},{"Flavor",type text},{"Scoops",Int64.Type},{"Amount",type number}},"en-US")
in
#"Changed Type"
Result: One table with 12 sales rows, six from Downtown and six from Harbor

Here’s what each step does:
- CSV Files keeps the CSV files that aren’t in the Archive folder (the same filter as Example 5).
- Added Shop adds the Shop column from the folder name.
- Added Data reads each file’s Content with the Csv.Document function and uses its first row as headers, so the Data column holds one table per file.
- Kept Columns and Expanded Data keep the Shop and Data columns, then stack the rows from all the files with the Table.ExpandTableColumn function.
- Changed Type sets the data types, because the expanded columns come in with no data type. The
"en-US"at the end tells Power Query that the amounts use a period as the decimal point, so 332.5 stays 332.5 on a computer that uses a decimal comma.
To add July, drop the new CSV file into the Downtown or Harbor folder and refresh. The query picks it up on its own, with the right shop name.
If you don’t need the Shop column, the Table.Combine function can stack the tables instead. Table.Combine(#"Added Data"[Data]) takes the Data column as a list of tables and stacks them in one go, without the select and expand steps.
For Excel files, use the Excel.Workbook function in the Added Data step instead of Csv.Document. It returns a table listing each file’s sheets and tables, so you first pick the sheet you want and then promote its headers.
Also leave out the ~$ files when you combine Excel files, as shown in Example 3.
Other Excel Articles You May Also Like:
- Web.Contents – Use Web.Contents in Power Query M to get data from a URL or API.
- Sql.Database – Use Sql.Database in Power Query M to connect to a SQL Server database.
- Combine CSV Files When Column Headers Don’t Match – Combine CSV files in Power Query when column headers don’t match.