title: How do I build a list of file names?
body: <p>I need to write an Ant target that appends together (comma-delimited) a list of '.jar' file names from a folder into a variable, which is later used as input to an outside utility.
  I am running into barriers of scope and immutability. I have access to ant-contrib, but unfortunately the version I am stuck with does not have access to the 'for' task. Here's what I have so far:</p>
  
  <pre><code>&lt;target name="getPrependJars"&gt;
      &lt;var name="prependJars" value="" /&gt;
      &lt;foreach param="file" target="appendJarPath"&gt;
          &lt;path&gt;
              &lt;fileset dir="${project.name}/hotfixes"&gt;
                  &lt;include name="*.jar"/&gt;
              &lt;/fileset&gt;
          &lt;/path&gt;         
      &lt;/foreach&gt;
  
      &lt;echo message="result ${prependJars}" /&gt;
  &lt;/target&gt;
  
  
  &lt;target name="appendJarPath"&gt;
      &lt;if&gt;
          &lt;equals arg1="${prependJars}" arg2="" /&gt;
          &lt;then&gt;
              &lt;var name="prependJars" value="-prependJars ${file}" /&gt;
          &lt;/then&gt;
          &lt;else&gt;
              &lt;var name="prependJars" value="${prependJars},${file}" /&gt;
          &lt;/else&gt;
      &lt;/if&gt;       
  &lt;/target&gt;
  </code></pre>
  
  <p>It seems that 'appendJarPath' only modifies 'prependJars' within its own scope. As a test, I tried using 'antcallback' which works for a single target call, but does not help me very much with my list of files.</p>
  
  <p>I realize that I am working somewhat against the grain, and lexical scope is desirable in the vast majority of instances, but i really would like to get this working one way or another. Does anybody have any creative ideas to solve this problem?</p>