Pavel Vlasov
Pavel Vlasov

Reputation: 4331

Problem with quoted filenames in Batch

Let I have a batch program:

SET FOO=C:\temp\%1
bar.exe %FOO%

When I call it with double quoted file name as an argument I get these quotes in the middle; and that fact prevents other programs from working correctly:

> fail.bat "aa bb.jpg"
SET FOO=C:\temp\"aa bb.jpg"
> bar.exe C:\temp\"aa bb.jpg"
cannot find file

How to get variable containing correct value "C:\temp\aa bb.jpg"?

Upvotes: 1

Views: 95

Answers (2)

jeb
jeb

Reputation: 82237

You can use %~1 instead, this removes the quotes from the parameter.
Then your code should look like

SET FOO="C:\temp\%~1"
bar.exe %FOO%

Upvotes: 2

Zombian
Zombian

Reputation: 1435

Try removing the drive letter as I have had issues with that in the past. Also does it work if the entire path name is in quotes not just the single item with spaces?

Upvotes: 0

Related Questions