0

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?

1
  • That is difficult to answer without seeing the batch file.
    – FrankPl
    Aug 16, 2013 at 20:28

2 Answers 2

2

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.

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.