How do I get a file path without extension in PowerShell?

前端 未结 5 1822
旧时难觅i
旧时难觅i 2021-01-17 15:29

I have an absolute path in a variable in my powershell 2.0 script. I want to strip off the extension but keep the full path and file name. Easiest way to do that?

So

5条回答
  •  逝去的感伤
    2021-01-17 16:01

    You should use the simple .NET framework method, instead of cobbling together path parts or doing replacements.

    PS> [System.IO.Path]::GetFileNameWithoutExtension($file)
    

    https://msdn.microsoft.com/en-us/library/system.io.path.getfilenamewithoutextension%28v=vs.110%29.aspx

提交回复
热议问题