1.

Solve : Batch parameters containing spaces?

Answer»

I am tearing my HAIR out with this. I have LOOKED at various suggested solutions but I can't get them to work.
I have a simple batch file (D:\Download\BackupList.txt) that contains folder names:
Brain Exerciser
Captures
CpuGproj

I have a batch file that just displays each line of the file. I can't get it to display the first line that contains spaces, it just displays Brain. I have tried using quotation marks and delims but I can't get it to work. I'm sure there's a simple answer but it eludes me. The batch file is:
For /F "tokens=1*" %%g in (D:\Download\BackupList.txt) do call :echoit %%g
goto :exit
:echoit
echo %1
goto :eof
:exit
pause

I would be grateful for any help. tiatokens=%* or tokens=%~1 perhaps?Quote from: CHman on January 22, 2010, 09:15:22 AM

Brain Exerciser
Captures
CpuGproj

The batch file is:
For /F "tokens=1*" %%g in (D:\Download\BackupList.txt) do call :echoit %%g
goto :exit
:echoit
echo %1
goto :eof
:exit

echo "%1"

Thanks for the replies.

Quote from: Treval on January 22, 2010, 10:14:36 AM
tokens=%* or tokens=%~1 perhaps?
The FOR finishes immediately when these are used.

Quote from: BillRichardson on January 22, 2010, 10:30:59 AM
echo "%1"
This just PUTS quotes round the Brain

The full string Brain Exerciser is not being passed to the echoit routine.Quote from: CHman on January 22, 2010, 09:15:22 AM
I'm sure there's a simple answer but it eludes me.

I am confused. Why don't you just do this? (below) Is there some reason you want to a simple thing in a complex way?

for /f "delims=" %%g in (D:\Download\BackupList.txt) do echo %%g

1. Textlines.txt

Code: [Select]I am tearing my hair out with this. I have looked at various suggested solutions but I can't get them to work.
I have a simple batch file (D:\Download\BackupList.txt) that contains folder names:

2. Showlines.bat

Code: [Select]@echo off
for /f "delims=" %%A in (textlines.txt) do echo %%A
3. Output:
Code: [Select]D:\Test\Batch>showlines.bat
I am tearing my hair out with this. I have looked at various suggested solutions but I can't get them to work.
I have a simple batch file (D:\Download\BackupList.txt) that contains folder names:

Quote from: CHman on January 22, 2010, 11:32:55 AM

The full string Brain Exerciser is not being passed to the echoit routine.


C:\batch>type chman.bat
Code: [Select]rem Brain Exerciser
rem Captures
rem CpuGproj
@echo off
For /F "delims=" %%g in (E:\Download\BackupList.txt) do echo %%g

pause
For /F "delims=" %%g in (E:\Download\BackupList.txt) do call :echoit "%%g"
goto :exit
goto :exit
:echoit
echo %1
goto :eof
:exit

Output:

C:\batch> chman.bat

C:\batch>rem Brain Exerciser

C:\batch>rem Captures

C:\batch>rem CpuGproj
Brain Exerciser
Captures
CpuGproj
Press any key to continue . . .
"Brain Exerciser"
"Captures"
"CpuGproj"
C:\batch>Brilliant. Thanks Salmon Trout and BillRichardson, I think you've cracked it.
It's the "delims=" that seems to do the trick.The DEFAULT delimiters are spaces. You can change the delimiters to any other character e.g. "delims=," makes the delimiter a comma, and "delims=" makes the delimiters the start and end of the line.
Quote from: CHman on January 22, 2010, 09:15:22 AM
For /F "tokens=1*" %%g in (D:\Download\BackupList.txt) do call :echoit %%g
goto :exit
:echoit
echo %1
goto :eof
:exit

The use of tokens and a call to a LABEL will work.
At least two tokens must be used. The delims between tokens is a space. When the first token is named %%g, the second token may be named %%h


Code: [Select]@echo off
For /F "delims=" %%g in (E:\Download\BackupList.txt) do echo %%g

pause

For /F "tokens=1,2 delims= " %%g in (E:\Download\BackupList.txt)do call:echoit %%g %%h

goto :exit
goto :exit
:echoit
echo %1 %2
goto :eof
:exit
RUN

C:\batch> chman2.bat
Brain Exerciser
Captures
CpuGproj
Press any key to continue . . .
Brain Exerciser
Captures
CpuGproj
C:\batch>


Discussion

No Comment Found