Forum Discussion

HennSarv's avatar
HennSarv
Helper I
5 years ago
Solved

Follder.Content and Folder.Files option

Hi people,

MIght someone give me hint to find some reference

Folder.Files(path as text, optional options as nullable record) as table
Folder.Contents(path as text, optional options as nullable record) as table

Both them shows parameter options, but I don't find any reference for those options?

What options I can use there and is there some option to include subfolders into response table
 
THanks in advance
Henn

PS! Recomentation for docs-writers - include that kind of info into docs

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

     

5 Replies

  • v-yingjl's avatar
    v-yingjl
    Community Support

    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.

     

  • mahoneypat's avatar
    mahoneypat
    Microsoft Employee

    Folder.Files includes subfolder content automatically (the other does not).  You can then filter further with the Folder Path column if needed.

    Regards,

    Pat

  • 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



    • Anonymous's avatar
      Anonymous
      Not applicable

      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