Forum Discussion

skurek's avatar
skurek
New Member
7 years ago

How to import files from different paths

Hi.

How to import files from different locations?

I have paths to files saved in Excel table.

I can import one path from Excel to PQ:

= Folder.Files(paths{0}[Column1])

but this method gets only one path to files.

 

how to write own function (?) to get in loop all folders to files?

14 Replies

  • Hi.

    How to import files from different locations?

    I have paths to files saved in Excel table.

    I can import one path from Excel to PQ:

    = Folder.Files(paths{0}[Column1])

    but this method gets only one path to files.

     

    how to write own function (?) to get in loop all folders to files?

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    You could create a separate query for each file, or simply create multiple "Source" lines. Either way, just append all of them together in the end. Not sure I can be more specific. ImkeF might have some thoughts as well.

     

    let
        Source = Csv.Document(File.Contents("C:\temp\powerbi\jobid.csv"),[Delimiter=",", Columns=2, Encoding=1252, QuoteStyle=QuoteStyle.None]),
        Source1 = Csv.Document(File.Contents("C:\temp\powerbi\months.csv"),[Delimiter=",", Columns=2, Encoding=1252, QuoteStyle=QuoteStyle.None]),
        #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
        #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"JobID", Int64.Type}, {"Date", type date}}),
        #"Appended Query" = Table.Combine({Source, Source1})
    in
        #"Appended Query"
    • ImkeF's avatar
      ImkeF
      Community Champion

      You can start from a table with one pathname in each row. Then you have to convert your From-Path-query into a function and apply it in a custom column. Just expand the columsn afterwards.

    • skurek's avatar
      skurek
      New Member

      file list is dynamical and i dont know how many files is in the table and i dont know files names...

      so i cant write separate query for each file...

      • ImkeF's avatar
        ImkeF
        Community Champion

        I don't understand your request:

         

        If you import from a folder, all files in that folder and all files in all its subfolders will be imported. UNLESS: You filter some files in them. So you just have to grab the uppermost path to grab all files in it.

         

        If you have any other kind of logic to identify what shall be imported, please try to explain better.