<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Damir's Corner - Development|Scripting</title>
    <link>http://www.damirscorner.com/</link>
    <description>Notes from Daily Encounters with Technology</description>
    <language>en-us</language>
    <copyright>Damir Arh, M. Sc.</copyright>
    <lastBuildDate>Tue, 24 Jul 2007 14:19:03 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.9074.18820</generator>
    <managingEditor>damir.arh@gmail.com</managingEditor>
    <webMaster>damir.arh@gmail.com</webMaster>
    <item>
      <trackback:ping>http://www.damirscorner.com/Trackback.aspx?guid=6440be26-d6e9-4d14-91f2-6f1d9c2831bd</trackback:ping>
      <pingback:server>http://www.damirscorner.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.damirscorner.com/PermaLink,guid,6440be26-d6e9-4d14-91f2-6f1d9c2831bd.aspx</pingback:target>
      <dc:creator>Damir Arh</dc:creator>
      <wfw:comment>http://www.damirscorner.com/CommentView,guid,6440be26-d6e9-4d14-91f2-6f1d9c2831bd.aspx</wfw:comment>
      <wfw:commentRss>http://www.damirscorner.com/SyndicationService.asmx/GetEntryCommentsRss?guid=6440be26-d6e9-4d14-91f2-6f1d9c2831bd</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Figuring this out took me much longer than it should. The following line in a batch
file will execute a command for each file in a directory:
</p>
        <div class="CodeFormatContainer">
          <pre class="csharpcode">
            <span class="kwrd">for</span> %%I <span class="kwrd">in</span> (C:\*.*) <span class="kwrd">do</span> echo
%%~nxI</pre>
        </div>
        <p>
I had to overcome two obstacles to make this work:
</p>
        <ul>
          <li>
When including the command in a batch file the % characters must be duplicated in
comparison to the syntax for executing the command directly from the
command line.</li>
          <li>
The ~nx prefix to the variable name causes only the filename with extension to be
used instead of the complete path.</li>
        </ul>
        <img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=6440be26-d6e9-4d14-91f2-6f1d9c2831bd" />
      </body>
      <title>Loop over files in directory from a batch file</title>
      <guid isPermaLink="false">http://www.damirscorner.com/PermaLink,guid,6440be26-d6e9-4d14-91f2-6f1d9c2831bd.aspx</guid>
      <link>http://www.damirscorner.com/LoopOverFilesInDirectoryFromABatchFile.aspx</link>
      <pubDate>Tue, 24 Jul 2007 14:19:03 GMT</pubDate>
      <description>&lt;p&gt;
Figuring this out took me much longer than it should. The following line in a batch
file will execute a command for each file in a directory:
&lt;/p&gt;
&lt;div class="CodeFormatContainer"&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;for&lt;/span&gt; %%I &lt;span class="kwrd"&gt;in&lt;/span&gt; (C:\*.*) &lt;span class="kwrd"&gt;do&lt;/span&gt; echo
%%~nxI&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
I had to overcome two obstacles to make this work:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
When including the command in a batch file the % characters must be duplicated in
comparison to the syntax&amp;nbsp;for executing the command directly&amp;nbsp;from&amp;nbsp;the
command line.&lt;/li&gt;
&lt;li&gt;
The ~nx prefix to the variable name causes only the filename with extension to be
used instead of the complete path.&lt;/li&gt;
&lt;/ul&gt;
&lt;img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=6440be26-d6e9-4d14-91f2-6f1d9c2831bd" /&gt;</description>
      <comments>http://www.damirscorner.com/CommentView,guid,6440be26-d6e9-4d14-91f2-6f1d9c2831bd.aspx</comments>
      <category>Development</category>
      <category>Development/Scripting</category>
    </item>
  </channel>
</rss>