How can I create an ant fileset which excludes certain directories based on the contents of the directory?
I use ant to create a distribution jar which has each localization in separate directories, some of which are incomplete and should not be released.
I would like to add something to the directory (for example a file named incomplete.flag
) so that ant excludes the directory. Then I can delete the file when translation is complete, and include it in the build without modifying build.xml.
Given this directory structure:
proj
+ locale
+ de-DE
+ en-US
+ fr-FR
This fileset excludes all incompelte.flag
files, but how can I exclude the entire directories that contain them?
<fileset dir="${basedir}">
<include name="locale/"/>
<exclude name="locale/*/incomplete.flag">
</fileset>
I can write an ant task if need be, but I'm hoping the fileset
can handle this use case.
it works for me with a jar target:
this code include all files in "classes.dir" but exclude the directory "client" from the jar.
I think one way is first to check whether your file exists and if it exists to exclude the folder from copy:
This should work also for the other languages.
There is actually an example for this type of issue in the Ant documentation. It makes use of Selectors (mentioned above) and mappers. See last example in http://ant.apache.org/manual/Types/dirset.html :
Selects all directories somewhere under
${workingdir}
which contain a${markerfile}
.Answer provided by user mgaert works for me. I think it should be marked as the right answer.
It works also with complex selectors like in this example:
Thus, having a directory structure like this:
the above dirset would contain only
(bar
doesn't match because of sub3 whilexyzzy
doesn't match because it's not a direct subdirectory oftargetdir
)You need to add a '/' after the dir name
This is possible by using "**" pattern as following.
the above 'exclude' will exclude all directories completely which contains incomplete.flag file.