Forum Discussion
Extract latest csv from folder with multiple gz
Hi,
i want to extract from the latest gz file in a folder the csv file and continue with transforming. But it won't work out.... can someone help out?
= let
Quelle = Folder.Files("C:\xyz\folder"),
#"Sortierte Zeilen" = Table.Sort(Quelle,{{"Date created", Order.Descending}}),
#"Beibehaltene erste Zeilen" = Table.FirstN(#"Sortierte Zeilen",1)
Decompressed = Binary.Decompress(Source, Compression.GZip),
#"Imported CSV" = Csv.Document(Decompressed,[Delimiter="", Encoding=1252),
in
#"Imported CSV"
Thanks
1 Reply
- rubayatyasminCommunity Champion
Hi, VTom
you need to add GetBinary = KeptFirstRow{0}[Content], before decompressing. to keep only the first row, which is the latest file.
so your modified code will be something like
let
Source = Folder.Files("C:\xyz\folder"),
SortedRows = Table.Sort(Source,{{"Date created", Order.Descending}}),
KeptFirstRow = Table.FirstN(SortedRows,1),
GetBinary = KeptFirstRow{0}[Content],
Decompressed = Binary.Decompress(GetBinary, Compression.GZip),
ImportedCSV = Csv.Document(Decompressed,[Delimiter=",", Encoding=1252])
in
ImportedCSVAlso, this tutorial will be helpful.