Windows shell 字符串操作(将反斜杠更改为斜杠)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2903416/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Windows shell string operations (changing backslash to slash)
提问by Matthias Hryniszak
I need to write a script that takes the current path (%~dp0), transforms backslashes into forward slashes and passes it further to some command.
我需要编写一个脚本,该脚本采用当前路径 (%~dp0),将反斜杠转换为正斜杠并将其进一步传递给某个命令。
Due to the environment I'm working in the only option that I have is windows shell (not Powershell where the issue would not a problem).
由于环境的原因,我使用的唯一选项是 windows shell(不是 Powershell,在那里问题不成问题)。
Is it even possible to do that?
甚至有可能这样做吗?
回答by Paused until further notice.
The set
command has a substitution feature:
该set
命令具有替换功能:
set a=C:\test\dir
set a=%a:\=/%
echo %a%
Results in:
结果是:
C:/test/dir