Search code examples
powershellfilepathtext-parsingends-with

Powershell command to trim path if it ends with "\"


I need to trim path if it ends with \.

C:\Ravi\

I need to change to

C:\Ravi

I have a case where path will not end with \ (Then it must skip).

I tried with .EndsWith("\"), but it fails when I have \\ instead of \.

Can this be done in PowerShell without resorting to conditionals?


Solution

  • no need to overcomplicate

    "C:\Ravi\".trim('\')