| 1. |
Solve : For loop endline deliminator? |
|
Answer» This is the current VERSION of the batch I was writing. However when it's parsing through either the file NAMES or the inlist if the file name has a space in it it is breaking it down into multiple objects, using the " " as a delim. In a for loop is there a way to make it delim at the end of a line as opposed to any white space? In a for loop is there a way to make it delim at the end of a line as opposed to any white space? In the for loop remove "tokens=* and delims=" By default the complete input line is read. for example: C:\batch>type lim.bat Code: [Select]echo off setlocal enabledelayedexpansion for /f %%i in (inList.txt) do ( set lit=MISSING echo lit = !lit! echo %%i ) Output: C:\batch> lim.bat lit = MISSING Roof.txt lit = MISSING Ceiling.txt lit = MISSING Ground.txt lit = MISSING Floor.txt lit = MISSING Noob.txt lit = MISSING Beginner.txt lit = MISSING DecentPlayer.txt Input: C:\batch>type inlist.txt Roof.txt Ceiling.txt Ground.txt Floor.txt Noob.txt Beginner.txt DecentPlayer.txt C:\batch>BillGreg, by default, delims is set to space. The program as given does not work for me in the XP command line. Quote from: Geek-9pm on March 01, 2010, 03:56:22 PM The program as given does not work for me in the XP command line.Maybe because for loops you one % sign on the command prompt. Not quite sure. Quote from: Grimbear13 on March 01, 2010, 09:53:05 AM In a for loop is there a way to make it delim at the end of a line as opposed to any white space? Post #1 is wrong. Fix with "delims=" C:\batch>type lim.bat Code: [Select]echo off setlocal enabledelayedexpansion for /f "delims=" %%i in (inList.txt) do ( echo %%i ) Output: C:\batch>lim.bat Roof.txt Ceiling.txt Ground.txt Floor.txt Noob.txt Beginner.txt DecentPlayer.txt January Snowy 02 February Rainy 15 March Sunny 25 Input: C:\batch>type inlist.txt Roof.txt Ceiling.txt Ground.txt Floor.txt Noob.txt Beginner.txt DecentPlayer.txt January Snowy 02 February Rainy 15 March Sunny 25 C:\batch> Quote from: greg on March 01, 2010, 04:23:29 PM You're welcome I'm sorry I got caught up in work yesterday and a collegue pointed out a possible issue. It wasn't the spaces in the code that were causing the issue. Whomever was naming the files that I was running this against was using an IRREGULAR dash. Even when copying the name directly it wasn't finding it. Thank You to everyone who replied. I thought that this script worked with spaces and I even checked it against an older job I did and it worked. |
|