| 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. Brain Exerciser 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
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 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> |
|