<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Who... What... Where... &#187; Batch File</title>
	<atom:link href="http://www.yeltuor.com/articles/tag/batch-file/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.yeltuor.com</link>
	<description>General things I find interesting</description>
	<lastBuildDate>Sun, 02 Aug 2009 09:58:13 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Batch File &#8211; For Loop</title>
		<link>http://www.yeltuor.com/articles/script/batch-file-for-loop/</link>
		<comments>http://www.yeltuor.com/articles/script/batch-file-for-loop/#comments</comments>
		<pubDate>Mon, 09 Feb 2009 22:02:52 +0000</pubDate>
		<dc:creator>shane</dc:creator>
				<category><![CDATA[Scripting Snippets]]></category>
		<category><![CDATA[Batch File]]></category>
		<category><![CDATA[Loop]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.yeltuor.com/?p=67</guid>
		<description><![CDATA[I will commonly write small batch files to automate tasks that are repetitive, due to this I find myself using the for loop a lot. Below are a few examples of when and where the for loop can be used effectively.
Looping through entries in a file
This example will take a standard text file (MyTextFile.txt) and [...]]]></description>
			<content:encoded><![CDATA[<div class="content">
<p class="MsoNormal">I will commonly write small batch files to automate tasks that are repetitive, due to this I find myself using the <em>for loop</em> a lot. Below are a few examples of when and where the for loop can be used effectively.</p>
<h3>Looping through entries in a file</h3>
<p>This example will take a standard text file (MyTextFile.txt) and then loop through all lines until the end of the file is reached. For each of the lines the first word (represented by <em>%%A</em>) will be printed out to the screen and ping&#8217;ed.</p>
<blockquote><p>FOR /F &#8220;tokens=1&#8243; %%A IN (C:\MyTextFile.txt) DO (</p>
<p>echo %%A</p>
<p>ping %%A</p>
<p>)</p></blockquote>
<p>An example of the text file is simply:</p>
<blockquote><p>COMPUTER01<br />
COMPUTER02<br />
COMPUTER03<br />
COMPUTER04</p></blockquote>
<p>By changing the <em>tokens</em> value, which word on a line that is used will change. By setting the value of tokens from <em>1</em> to <em>1,2</em> both the first and second words per line will be available via the parameters <em>%%A</em> and <em>%%B</em>. When using the following input file, within the loop %%A will be the computer name and %%B will be the IP address.</p>
<blockquote><p>COMPUTER01 192.168.1.100<br />
COMPUTER02 192.168.1.101<br />
COMPUTER03 192.168.1.102</p></blockquote>
<p>To ignore selected lines, i.e. lines that are actually comments use the <em>eol </em>parameter, the following for loop will ignore all lines that start with a colon:</p>
<blockquote><p>FOR /F &#8220;tokens=1 eol=:&#8221; %%A IN (C:\MyTextFile.txt) DO (</p>
<p>echo %%A</p>
<p>)</p></blockquote>
<p>If the input file has a number of header lines that should not be included the <em>skip</em> parameter should be used, for following will exclude the first 3 files of the input file:</p>
<blockquote><p>FOR /F &#8220;tokens=1 eol=: skip=3&#8243; %%A IN (C:\MyTextFile.txt) DO (</p>
<p>echo %%A</p>
<p>)</p></blockquote>
<p>To override the default delimiters (space and tab) the <em>delims</em> parameter should be used. The following will ignore the space delimiter and instead delimiter by comma:</p>
<blockquote><p>FOR /F &#8220;tokens=1 delims=,&#8221; %%A IN (C:\MyTextFile.txt) DO (</p>
<p>echo %%A</p>
<p>)</p></blockquote>
</div>

	Tags: <a href="http://www.yeltuor.com/articles/tag/batch-file/" title="Batch File" rel="tag">Batch File</a>, <a href="http://www.yeltuor.com/articles/tag/loop/" title="Loop" rel="tag">Loop</a>, <a href="http://www.yeltuor.com/articles/tag/windows/" title="Windows" rel="tag">Windows</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.yeltuor.com/articles/script/batch-file-for-loop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
