I need to pass parameter line AB CD
to a batch file from the command line. This parameter refer to a file name.
If I use use AB CD
the script just pick the first part and return Unable to find the file AB.txt
If I put quote around my parameters like "AB CD"
the I got
"AB CD".txt
Illegal characters in path.
When you send arguments, those with poison or space characters need to be doublequoted. Inside your batch file, if you no longer need the surrounding doublequotes, you'd remove them by using %~5 instead of %5 . Additionally the recommended syntax for the set command is Set "VariableName=VariableValue" .
Use quotation marks when specifying long filenames or paths with spaces. For example, typing the copy c:\my file name d:\my new file name command at the command prompt results in the following error message: The system cannot find the file specified. The quotation marks must be used.
Use double percent signs ( %% ) to carry out the for command within a batch file. Variables are case sensitive, and they must be represented with an alphabetical value such as %a, %b, or %c. ( <set> ) Required. Specifies one or more files, directories, or text strings, or a range of values on which to run the command.
you can use %~1 instead of %1
e.g a test.bat with :
echo %~1
then a call to test "abc de"
will display :
abc de
what you can do is
>batch.bat "ab cd.txt"
When the parameters contain whitespace, you can enclose them in quotes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With