Forum Discussion
Zdenek_Moravec
Feb 09, 2021Brass Contributor
Power Query - Split folder path with different structure into same columns
Dear colleagues, I want to create a list of folders and files and split the folder names into columns. Unfortunatelly the structure of all subfolders is not the same. Example: C:\EUROPE\GERMANY\20...
- Feb 09, 2021
Slightly different variant (without transition from letter to number), but with same assumption we have only 4 parts and only second one (country) could be missed.
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content], #"Exclude Drive" = Table.AddColumn( Source, "path", each Text.AfterDelimiter([FileName], ":\"), type text ), #"Get Region" = Table.SplitColumn( #"Exclude Drive", "path", Splitter.SplitTextByEachDelimiter({"\"}, QuoteStyle.Csv, false), {"Region", "Txt"} ), #"Get File" = Table.SplitColumn( #"Get Region", "Txt", Splitter.SplitTextByEachDelimiter({"\"}, QuoteStyle.Csv, true), {"Txt", "File"} ), #"Get Country" = Table.AddColumn( #"Get File", "Country", each Text.BeforeDelimiter([Txt], "\", {0, RelativePosition.FromEnd}), type text ), #"Get Year" = Table.AddColumn( #"Get Country", "Year", each Text.AfterDelimiter([Txt], "\", {0, RelativePosition.FromEnd}), type text ), #"Keep Final" = Table.SelectColumns( #"Get Year", {"Region", "Country", "Year", "File"} ) in #"Keep Final"
Riny_van_Eekelen
Feb 09, 2021Platinum Contributor
Zdenek_Moravec A quick-and-dirty solution attached.
- Zdenek_MoravecFeb 09, 2021Brass Contributor
Hello Riny_van_Eekelen
Thank You for the hint. I understand, that this task has not an universal solution, but the usage of SplitTextByCharacterTransition can be usefull. I have never seen this function in online trainings. By the debugging I found, that the structure is slightly different and even worser for SplitTextByCharacterTransition - first year, then countries, finally files.
C:\EUROPE\2019\GERMANY\file1.docx C:\EUROPE\2020\GERMANY\file2.docx C:\EUROPE\2019\FRANCE\file3.docx C:\EUROPE\2020\FRANCE\file4.docx C:\AMERICA\2019\file5.docx C:\AMERICA\2020\file6.docx