英文:
Get the extension from a filepath
问题
I need to test the extension of the imported file as to if it is CSV
or XLSX
.
I am trying:
FP = Text.AfterDelimiter([Path], ".", {0, RelativePosition.FromEnd}),
let
FilePath = Excel.CurrentWorkbook(){[Name="fp"]}[Content]{0}[TheFilePath],
FP = Text.AfterDelimiter([FilePath], ".", {0, RelativePosition.FromEnd}),
Source = Excel.Workbook(File.Contents(FilePath))
in Source
But I get the error:
There is an unknown identifier. Did you use the [field] shorthand for a _[field] outside of an 'each' expression?
I did try:
FP = Text.AfterDelimiter(_[FilePath], ".", {0, RelativePosition.FromEnd})
This did not correct the issue.
英文:
I need to test the extension of the imported file as to if it is CSV
or XLSX
I am trying
FP = Text.AfterDelimiter([Path], ".", {0, RelativePosition.FromEnd}),
let
FilePath = Excel.CurrentWorkbook(){[Name="fp"]}[Content]{0}[TheFilePath],
FP = Text.AfterDelimiter([FilePath], ".", {0, RelativePosition.FromEnd}),
Source = Excel.Workbook(File.Contents(FilePath))
in Source
But I get the error
There is an unknown identifier. Did you use the [field] shorthand for a _[field] outside of an 'each' expression?
I did try
FP = Text.AfterDelimiter(_[FilePath], ".", {0, RelativePosition.FromEnd})
This did not correct the issue
答案1
得分: 1
这是一个查找最后一个句点后面部分的代码:
let FilePath = Excel.CurrentWorkbook(){[Name="fp"]}[Content]{0}[TheFilePath],
Extension = List.Last(Text.Split(FilePath, "."))
in Extension
英文:
How about this, which finds the part after the last period?
let FilePath = Excel.CurrentWorkbook(){[Name="fp"]}[Content]{0}[TheFilePath],
Extension=List.Last(Text.Split(FilePath,"."))
in Extension
答案2
得分: 1
= Table.AddColumn(#"AddPathColumn", "Extension", each if Text.Contains([Path], ".") then Text.AfterDelimiter([Path], ".", {0, RelativePosition.FromEnd}) else "no extension", type text)
英文:
Here is an elegant way I just solved this for paths where some fines have no extension. Hope it helps someone.
= Table.AddColumn(#"AddPathColumn", "Extension", each if Text.Contains([Path], ".") then Text.AfterDelimiter([Path], ".", {0, RelativePosition.FromEnd}) else "no extension", type text)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论