View Full Version : Batch Script - For /f - Spaces in file path problem

23-04-2010, 12:55 PM
I am trying to use a vba script to batch print documents listed in at .txt file.
The script works except when there is a space in the path of the .txt file that contains the list of documents to print. It returns an error saying it can't find the file.
All the info I can find by trawling the forums says just put "" around the file path - but when I do this it prints the contents of the .txt file - not the documents themselves.

Can anyone suggest a workaround for this problem? Is there any character I can put in in place of the space that will make it work?

Here is my batch script:

@echo off & setlocal
for /f "delims=" %%a in (h:\my documents\printscript\testlist.txt) do (
"h:\my documents\printscript\Printdoc.vbs" "%%a"

NB: It works when there is no space in the .txt path, and it works when there are spaces in the file names of the documents its printing - just not when the .txt location has the spaces.

Speedy Gonzales
23-04-2010, 01:17 PM
Should have added it to the other post (http://pressf1.co.nz/showthread.php?t=109021)

23-04-2010, 01:23 PM
Thanks Speedy - its a different script and a different problem so I thought it could do with a different thread.
Any Suggestions?

Speedy Gonzales
23-04-2010, 01:31 PM
Its the same thing tho. Umm nope wouldnt have a clue. I dont use any commands to copy anything

23-04-2010, 02:47 PM
Use the "usebackq" option (from HELP FOR):

usebackq - specifies that the new semantics are in force,
where a back quoted string is executed as a
command and a single quoted string is a
literal string command and allows the use of
double quotes to quote file names in

This requires strings (as opposed to file names) within the parentheses to have single quotes, not double quotes. Then all you have to do is quote the list file as follows:

for /f "usebackq delims=" %%a in ("h:\my documents\printscript\testlist.txt") do ...

23-04-2010, 02:54 PM
Excellent! That works perfectly.
Thanks MushHead :-)