1.

Solve : For loop endline deliminator?

Answer» <html><body><p>This is the current <a href="https://interviewquestions.tuteehub.com/tag/version-1444891" style="font-weight:bold;" target="_blank" title="Click to know more about VERSION">VERSION</a> of the batch I was writing.  However when it's parsing through either the file <a href="https://interviewquestions.tuteehub.com/tag/names-237999" style="font-weight:bold;" target="_blank" title="Click to know more about NAMES">NAMES</a> 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?<br/><br/> Code: <a>[Select]</a>echo off<br/>color 0A<br/><br/>if exist !MissingFiles.txt del !MissingFiles.txt<br/><br/>setlocal enabledelayedexpansion<br/>for /f "tokens=* delims=" %%i in (inList) do (<br/>  set lit=MISSING<br/><br/>  for /f "tokens=* delims=" %%x in ('dir . /s /b') do (<br/>    if %%i==%%~nx%%~xx set lit=CHECK<br/>  )<br/><br/>  echo %%i - !lit! &gt;&gt; !MissingFiles.txt<br/>  set lit=MISSING<br/>)<br/><br/>if exist !ExtraFiles.txt del !ExtraFiles.txt<br/><br/>setlocal enabledelayedexpansion<br/>for /f "tokens=* delims=" %%j in ('dir . /s /b') do (<br/>  set lit2=EXTRA<br/><br/>  for /f "tokens=* delims=" %%y in (inList) do (<br/>    if %%y==%%~nj%%~xj set lit2=CHECK<br/>  )<br/>  echo %%~nj%%~xj - !lit2! &gt;&gt; !temp.txt<br/>  set lit2=EXTRA<br/>)<br/><br/>find "." !temp.txt | find /i /v ".doc" | find /i /v ".<a href="https://interviewquestions.tuteehub.com/tag/xls-747397" style="font-weight:bold;" target="_blank" title="Click to know more about XLS">XLS</a>" | find /i /v ".rtf" | find /i /v "MissingFiles.txt" &gt;&gt; !ExtraFiles.txt<br/><br/>del !temp.txt<br/><br/>endlocal Quote from: Grimbear13 on March 01, 2010, 09:53:05 AM</p><blockquote> In a for loop is there a way to make it delim at the end of a line as opposed to any white space?<br/></blockquote> <br/>In the for loop remove "tokens=* and delims="  By default the complete input line is read.<br/><br/>for example:<br/><br/><br/>C:\batch&gt;type  lim.bat<br/> Code: <a>[Select]</a>echo off<br/><br/>setlocal enabledelayedexpansion<br/>for /f  %%i in (inList.txt) do (<br/>  set lit=MISSING<br/>echo lit = !lit!<br/>echo %%i<br/>)<br/><strong>Output:</strong><br/><br/>C:\batch&gt; lim.bat<br/>lit = MISSING<br/>Roof.txt<br/>lit = MISSING<br/>Ceiling.txt<br/>lit = MISSING<br/>Ground.txt<br/>lit = MISSING<br/>Floor.txt<br/>lit = MISSING<br/>Noob.txt<br/>lit = MISSING<br/>Beginner.txt<br/>lit = MISSING<br/>DecentPlayer.txt<br/><br/><strong>Input:</strong><br/><br/>C:\batch&gt;type inlist.txt<br/>Roof.txt<br/>Ceiling.txt<br/>Ground.txt<br/>Floor.txt<br/>Noob.txt<br/>Beginner.txt<br/>DecentPlayer.txt<br/><br/><br/>C:\batch&gt;BillGreg, by default, delims is set to space. The program as  given does not work for me in the <a href="https://interviewquestions.tuteehub.com/tag/xp-747558" style="font-weight:bold;" target="_blank" title="Click to know more about XP">XP</a> command line.  <br/> Quote from: Geek-9pm on March 01, 2010, 03:56:22 PM<blockquote>The program as  given does not work for me in the XP command line.  <br/><br/></blockquote> 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<blockquote> In a for loop is there a way to make it delim at the end of a line as opposed to any white space?<br/></blockquote> <br/>Post #1 is wrong.  Fix with  "delims="<br/><br/><br/>C:\batch&gt;type  lim.bat<br/> Code: <a>[Select]</a>echo off<br/><br/>setlocal enabledelayedexpansion<br/>for  /f "delims=" %%i in (inList.txt) do (<br/>echo %%i<br/>)<br/><strong>Output:</strong><br/>C:\batch&gt;lim.bat<br/>Roof.txt<br/>Ceiling.txt<br/>Ground.txt<br/>Floor.txt<br/>Noob.txt<br/>Beginner.txt<br/>DecentPlayer.txt<br/>January Snowy 02<br/>February Rainy 15<br/>March Sunny 25<br/><br/><br/><strong>Input:</strong><br/><br/>C:\batch&gt;type inlist.txt<br/>Roof.txt<br/>Ceiling.txt<br/>Ground.txt<br/>Floor.txt<br/>Noob.txt<br/>Beginner.txt<br/>DecentPlayer.txt<br/>January Snowy 02<br/>February Rainy 15<br/>March Sunny 25<br/><br/><br/><br/>C:\batch&gt; Quote from: greg on March 01, 2010, 04:23:29 PM<blockquote></blockquote> 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 <a href="https://interviewquestions.tuteehub.com/tag/irregular-2749380" style="font-weight:bold;" target="_blank" title="Click to know more about IRREGULAR">IRREGULAR</a> dash.  Even when copying the name directly it wasn't finding it.  Thank You to everyone who replied.<br/><br/>I thought that this script worked with spaces and I even checked it against an older job I did and it worked.</body></html>


Discussion

No Comment Found