开发者

Problem with quoted filenames in Batch

开发者 https://www.devze.com 2023-03-22 07:06 出处:网络
Let I have a batch program: SET FOO=C:\\tem开发者_高级运维p\\%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 oth

Let I have a batch program:

SET FOO=C:\tem开发者_高级运维p\%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"?


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%


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消