Martin Braun
Martin Braun

Reputation: 12579

Escape the content of a variable

In my batch script I need to pass the current directory path to a program, escaped.

So, when my batch script is running in C:\Program Files\ it has to pass C:\\Program Files\\ to the called program.

How can I do that? Many thanks.

Background: The called program expects a replacement string for a regex operation, thus it will expect a group parameter when using \ only. The data that will be targeted by the regex operation is used by a software that won't accept relative paths or environment variables.

Upvotes: 0

Views: 73

Answers (1)

Paul
Paul

Reputation: 2710

My first guess is %~dp0 the current path where the batch are located But there is also %CD%, the current working directory.

try something like:

@echo off
setlocal
set "x=%CD%"
set "x=%x:\=\\%"
echo %x%

as mentioned by @joey you can directly call the current directory like this %CD:\=\\%

Upvotes: 2

Related Questions