Reputation:
I would like to perform a string replace on the arguments given to my batch file. For example, replacing the %~dp0
argument from back slashes to forward slashes.
I have tried: %~dp0:\=/
and %~dp0:\=/%
, both do not replace the slashes. The only possible solution I can do is messy:
set dir=%~dp0
set dir=%dir:\=/%
Is there a better way to do it without setting a separate variable and hopefully in a single line?
Upvotes: 0
Views: 627
Reputation: 3900
String manipulations do not work for parsed arguments (%1
) or for
loop tokens (%%i
).
It is generally considered bad practice to not save your parsed arguments into named variables for two reasons:
Readability - transferring your arguments into named variables will increase your ability to debug and understand your code after you have written it.
Overwriting - any call:function param1 param2
occurrences in your scripts will overwrite the argument values within that scope.
Upvotes: 2