Forum Discussion
Follder.Content and Folder.Files option
- 5 years ago
Hi HennSarv ,
About the optional paremeter in Folder.Files() function, the official document has not explained it in details.
Based on my test, this parameter is about restricting power bi to get data when the file in the folder is opened / accessed.
For example, I have created two queries both connecting to the same folder, one of the parameter is set as true, another is set as false.
When I do not open any files in the folder, I can get the data from both queries. Both of them can import data into power bi:
When I open the file in the folder and refresh the query in power bi, the query which parameter is set as true will get IO errors like below while the false parameter can get data normally:
In addition, if the parameter is null by default, the result is the same as when the parameter is false.
Hopes it could help you to understand this optional parameter.
Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-yingjl - thanks for explanation. It helps lot
I looked actually for recurse-like option and I craeted now some sample PowerQuery function - might be interesting. Nice to have this functionality 'ready-from-box'
DirContent = // this is function-query name
// rest is function-query body
(path as text) as table =>
let
Source = Folder.Contents(path),
Folders = Table.SelectRows(Source, each ([Attributes][Directory] = true)),
Step1 = Table.SelectColumns(Folders,{"Name", "Folder Path"}),
Step2 = Table.AddColumn(Step1, "DirContent", each DirContent([Folder Path]& [Name])),
Step3 = Table.RemoveColumns(Step2,{"Folder Path", "Name"}),
Expanded = Table.ExpandTableColumn(Step3, "DirContent", {"Content", "Name", "Extension", "Date accessed", "Date modified", "Date created", "Attributes", "Folder Path"}, {"Content", "Name", "Extension", "Date accessed", "Date modified", "Date created", "Attributes", "Folder Path"}),
Files = Table.SelectRows(Source, each ([Attributes][Directory] = false)),
Result = Table.Combine({Files,Expanded})
in
Result
I think Step2 may need to look like this:
Step2 = Table.AddColumn(Step1, "DirContent", each @DirContent([Folder Path]& [Name])),
Without @ sign self-reference may not work.
Kind regards,
JB