powershell - extract file name and extension

前端 未结 9 911
温柔的废话
温柔的废话 2020-12-24 04:09

I need to extract file name and extension from e.g. my.file.xlsx. I don\'t know the name of file or extension and there may be more dots in the name, so I need to search the

9条回答
  •  情书的邮戳
    2020-12-24 04:36

    As of PowerShell 6.0, Split-Path has an -Extenstion parameter. This means you can do:

    $path | Split-Path -Extension
    

    or

    Split-Path -Path $path -Extension
    

    For $path = "test.txt" both versions will return .txt, inluding the full stop.

提交回复
热议问题