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? 回答1: no need to overcomplicate "C:\Ravi\".trim('\') 回答2: Consider using TrimEnd instead (especially if you are working with UNC Path): "C:\Ravi\".TrimEnd('\') 回答3: You mention needing to differentiate between paths