Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ant: How do I interate over all subfolders and perform a task in ant

Tags:

loops

ant

Currently I do

<foreach list="${myfolders}" target="bundle"
     param="worksheet" inheritall="true"/>

to execute the target "bundle" on a list of folders. However the problem is I need to set this list. How do I use Ant to just loop through all the folders given the parent directory?

If there is a way to do this and also exclude specific folders that would be even better. Thanks.

like image 827
Solomon Avatar asked Jun 06 '11 15:06

Solomon


1 Answers

You can provide a <dirset> for the <foreach> task to operate on:

 <foreach target="bundle" param="worksheet" inheritall="true">
      <path>
          <dirset dir="${subDir}">
               <include name="*"/>
          </dirset>
      </path>
 </foreach>

Notice that the list parameter isn't used when I do it this way.

You can't use <dirset> directly under the <foreach> as you can with <fileset>. However, you can put the <dirset> under the <path> as shown above. The <include name="*"/> prevents recursing down the directory tree.

like image 94
David W. Avatar answered Nov 15 '22 11:11

David W.