Search code examples
antbuildfileset

create a fileset of all files matching a pattern, excluding files with a specific sibling file


I would like to create a fileset of files matching a specific pattern, but exclude from this set any files which have a specific other file in the same directory.

E.g., I would like a fileset which matches all ./*/file.xml files, like:

<fileset dir="${some.dir}" includes="*/file.xml" />

... but I want to exclude any file.xml files which are in the same director as an ignore.this file.

So if the dir structure is:

foo/file.xml
bar/file.xml
bar/ignore.this

... the the file.xml in foo will be selected, but bar will not.


Solution

  • You can use a fileset with a present selector with a mapper:

    <fileset dir="${some.dir}" includes="*/file.xml">
        <present targetdir="${some.dir}" present="srconly">
            <mapper type="regexp" from="^(.*)/.*" to="\1/ignore.this" />
        </present>
    </fileset>
    

    That is, include only files called file.xml where there is no corresponding file in the same directory called ignore.this.