Sub topic 2
Connecting to a folder
This chapter assumes you are comfortable with Excel tables and the Data ribbon, and that you know what CSV and .xlsx files are. You also need Excel 2016 or later, or Microsoft 365, because Power Query is built in. Here you connect to a folder and look at what the connector returns. Filtering and combining come in later chapters.
What the From Folder connector does
The From Folder connector does not open any file. It reads the folder and returns one row per file it finds. Each row holds the file's name, its type, its dates, and its raw contents as a binary value. Combining happens in a later step.
The connector searches the folder and all its subfolders. Files in nested folders appear in the list too. This surprises many people, so keep it in mind.
Connect to a folder
- In Excel, open the Data tab.
- Choose Get Data > From File > From Folder.
- Click Browse, pick the folder (for example
C:\Data\Sales), and click OK. - Excel shows a preview of the file list. Choose Transform Data to open the Power Query Editor.
The preview dialog also offers Combine and Load. For now, choose Transform Data so you can see the list before anything is merged.
What the generated query looks like
In the editor, the Source step shows the folder call. Open the formula bar or the Advanced Editor and you will see:
let
Source = Folder.Files("C:\Data\Sales")
in
SourceFolder.Files takes a single argument, the folder path as text. It returns a table with these columns:
| Column | Contents |
|---|---|
| Content | The file's data as a binary value |
| Name | The file name, such as `2026-01.csv` |
| Extension | The file type with a leading dot, such as `.csv` |
| Date accessed | When the file was last opened |
| Date modified | When the file was last changed |
| Date created | When the file was created |
| Attributes | A record of file flags, such as read-only |
| Folder Path | The folder that holds the file, ending in a backslash |
The next chapter covers these columns in detail.
Common errors at this stage
- The path does not exist. Excel reports a
DataSource.Error. Check the spelling, and check that you can reach the drive or network share. - Unexpected extra rows. Files from subfolders, and temporary files, are included. Temporary files are created while a workbook is open in Excel and have names starting with
~$. You will filter these out in the next chapters. - An empty list. The folder has no files, or the path points to the wrong level.
- A cloud path. A SharePoint or OneDrive folder needs a different connector.
Folder.Filesis for paths that Windows can see.
Exercise
You connect to C:\Data\Sales, which contains three CSV files and one subfolder with two more CSV files. How many rows does the Source step return, and which column tells you where each file sits?
Show answer
Five rows, because the connector includes files in subfolders. The Folder Path column shows the folder each file is in.