James
James

Reputation: 111

Remove enclosing double quotes from a parameter passed to a batch file

I am calling a batch file like this:

test.bat C:\

The C:\ parameter is passed to a command within the batch file like this:

start program.bat "%1"

I am finding that program.bat is starting like this:

program.bat "C:\"

Is it possible to remove the enclosing quotation marks from the parameter so that program.bat receives C:\ instead of "C:\"?

Upvotes: 3

Views: 619

Answers (1)

Andriy M
Andriy M

Reputation: 77657

%1 evaluates to the first parameter as-is. That is, if the parameter is enclosed in quotation marks, they will be preserved.

%~1 strips the quotation marks before evaluating.

So, use %~1 in program.bat where you need to use the value of the first parameter without quotation marks.

Upvotes: 3

Related Questions