How to list subdirectories of the first level only in Ant?

Using Ant, how can I list subfolders only from the first level and not descend from the directory tree?

say that I have:

dir1 -- dir21 ----dir211 -- dir22 <dirset dir="dir1"/> 

will display all directories, including dir211 . How can i avoid this?

+4
source share
2 answers

Use dirset as follows:

 <dirset dir="dir" includes="*"/> 

or

 <dirset dir="dir1"> <include name="*"/> </dirset> 

EDIT after comment

includes attribute and nested include name should be equivalent, here are some snippet running on my windows machine, given C: \ foo \ bar:

 <project> <echo> ${ant.version} ${java.version} ${os.name} </echo> <dirset dir="c:/foo" includes="*" id="foobar" /> <echo>${toString:foobar}</echo> <dirset dir="c:/foo" id="foobaz"> <include name="*" /> </dirset> <echo>${toString:foobaz}</echo> </project> 

:

 Buildfile: C:\rosebud\AntTest\tryme.xml [echo] Apache Ant(TM) version 1.8.2 compiled on December 20 2010 [echo] 1.7.0_02 [echo] Windows 7 [echo] [echo] bar [echo] bar BUILD SUCCESSFUL 
+5
source

I wanted to include a date selector in my dirset and select only the subdirectories of the root directory, so I could not use includes="*" . My solution was to use the <depth> selector

 <dirset dir="/myroot" excludes="*/*/**"> <date datetime="${cuttoff_time}" pattern="${timeformat}" when="before" checkdirs="true" /> <depth max="1" /> </dirset> 
0
source

Source: https://habr.com/ru/post/1397376/


All Articles