Where your batch file has %1
or "%1"
replace them with "%~1"
%~1
removes any quotes that may be around the string, and "%~1"
replaces all strings with the quotes so that spaces and poison characters are protected.
質問
I am required to input a file path for a batch file I made.
C:\PATH\TO\DESKTOP>Batch "File Path With Spaces"
The batch file uses %1. I believe the spaces in the file path is causing problems. I tried messing with quotation marks, no luck.
Does anyone know?
解決
Where your batch file has %1
or "%1"
replace them with "%~1"
%~1
removes any quotes that may be around the string, and "%~1"
replaces all strings with the quotes so that spaces and poison characters are protected.
他のヒント
If you do not require any other arguments its very simple:
In your batch file say you wanted to echo "text" into a file. Instead of referring to the argument as %1
refer to it as %*
(which includes %1 %2 %3 %4 %5 %6 %7 %8 %9 ...
).
C:\PATH\TO\DESKTOP>Batch C:\users\%username%\file name with spaces\File Name.txt
and in Batch.bat:
Echo "text" >> "%*"
And your done. Just remember to surround the %*
with double quotes and you should be fine!
Mona