title: MSBuild: Stepping through an array
body: <p>I have a script that does a directory listing and puts it in with the newest entry first.  I then want to step through the array looking into that directory for a file and if it exists, stop, but if it doesn't, go to the next item of the array.  There are many directories under C:\Foo</p>
  
  <p>How do I do that?</p>
  
  <pre><code>&lt;PropertyGroup&gt;
      &lt;RootDir&gt;C:\Foo&lt;/RootDir&gt;
      &lt;OutputFile&gt;C:\Output.txt&lt;/OutputFile&gt;
  &lt;/PropertyGroup&gt;
  
  &lt;Target Name="Generate"&gt;
      &lt;Exec Command="dir &amp;quot;$(RootDir)&amp;quot; /ad /o-d /b &gt; &amp;quot;$(OutputFile)&amp;quot;" /&gt;
      &lt;ReadLinesFromFile File="$(OutputFile)"&gt;
          &lt;Output TaskParameter="Lines" ItemName="OutputLines"/&gt;
      &lt;/ReadLinesFromFile&gt;
      &lt;Message Text="@(OutputLines-&gt;'%(Identity)', '%0a%0d')" /&gt;
  &lt;/Target&gt;
  </code></pre>
  
  <p>So OutputLines has the array and I want to start at the first location of the array (i.e. C:\Foo\Dir1) and look for the file abc.zip.  If that exists, then copy that file to a different location and if not go to the next item (i.e. C:\Foo\Dir2).</p>
  
  <p>Thanks.  Any help is appreciated.  Still very new to MSBuild.</p>