如果Powershell命令以"\"结尾,则修剪路径 [英] Powershell command to trim path if it ends with "\"

查看:187
本文介绍了如果Powershell命令以"\"结尾,则修剪路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果路径以\结尾,则需要修整路径.

I need to trim path if it ends with \.

C:\Ravi\

我需要更改为

C:\Ravi

我遇到的情况是路径不会以\结尾(然后必须跳过).

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

我尝试使用.EndsWith("\"),但是当我使用\\而不是\时,它失败.

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

这可以在PowerShell中完成而无需求助于条件吗?

Can this be done in PowerShell without resorting to conditionals?

推荐答案

无需过于复杂

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

这篇关于如果Powershell命令以"\"结尾,则修剪路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆