Forum Discussion
doctornick0
7 years agoFrequent Visitor
Import CSV retain path and file name
Hi, everybody! I am trying to import a single CSV file via Power Query and retain the filename and path data, but I'm having a tough time adding a step that gets me that information. Because the...
- 7 years ago
Hi doctornick0 ,
We can get the file from Folder to work on it. M code for your reference.
let Source = Folder.Files("D:\Case\20190313\test"), #"Removed Columns" = Table.RemoveColumns(Source,{"Extension", "Date accessed", "Date modified", "Date created"}), #"Filtered Hidden Files1" = Table.SelectRows(#"Removed Columns", each [Attributes]?[Hidden]? <> true), #"Invoke Custom Function1" = Table.AddColumn(#"Filtered Hidden Files1", "Transform File from test (2)", each #"Transform File from test (2)"([Content])), #"Expanded Transform File from test (2)" = Table.ExpandTableColumn(#"Invoke Custom Function1", "Transform File from test (2)", {"col1", "col2", "col3"}, {"Transform File from test (2).col1", "Transform File from test (2).col2", "Transform File from test (2).col3"}), #"Removed Columns1" = Table.RemoveColumns(#"Expanded Transform File from test (2)",{"Content", "Attributes"}) in #"Removed Columns1"Regards,
Frank
v-frfei-msft
Community Support
7 years agoHi doctornick0 ,
We can get the file from Folder to work on it. M code for your reference.
let
Source = Folder.Files("D:\Case\20190313\test"),
#"Removed Columns" = Table.RemoveColumns(Source,{"Extension", "Date accessed", "Date modified", "Date created"}),
#"Filtered Hidden Files1" = Table.SelectRows(#"Removed Columns", each [Attributes]?[Hidden]? <> true),
#"Invoke Custom Function1" = Table.AddColumn(#"Filtered Hidden Files1", "Transform File from test (2)", each #"Transform File from test (2)"([Content])),
#"Expanded Transform File from test (2)" = Table.ExpandTableColumn(#"Invoke Custom Function1", "Transform File from test (2)", {"col1", "col2", "col3"}, {"Transform File from test (2).col1", "Transform File from test (2).col2", "Transform File from test (2).col3"}),
#"Removed Columns1" = Table.RemoveColumns(#"Expanded Transform File from test (2)",{"Content", "Attributes"})
in
#"Removed Columns1"
Regards,
Frank
doctornick0
7 years agoFrequent Visitor
Good call, I then just filtered the folder for the file I actually wanted, which actually works out well, I can pass the file name via code to the query in that case.