I need to write a script that takes the current path (%~dp0), transforms backslashes into forward slashes and passes it further to some command.
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).
Is it even possible to do that?
Press \/ to change every backslash to a forward slash, in the current line. Press \\ to change every forward slash to a backslash, in the current line.
The reason Microsoft is backwards on this goes back to MS-DOS 2.0 (DOS 1.0 had no directory hierarchy), which used a backslash to stay compatible with Dos 1.0 commands, which used slash for command line switches.
To replace all forward slashes in a string:Call the replace() method, passing it a regular expression that matches all forward slashes as the first parameter and the replacement string as the second. The replace method will return a new string with all forward slashes replaced.
You usually use " / " instead of the " # ", but as long as it is there, it doesn't matter. I am writing this on a windows PC so I hope it is right, you may have to escape the slashes with another slash. sed explained, the -e lets you edit the file in place. You can use -i to create a backup automatically.
The set
command has a substitution feature:
set a=C:\test\dir set a=%a:\=/% echo %a%
Results in:
C:/test/dir
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With