antdirectoryfileset

Delete fileset filenames, but in different directory


So I have a fileset containing files in one directory:

<fileset id="modules" dir="${modules.dir}">
    <include name="core*.jar"/>
    <include name="fileset*.jar"/>
    <include name="upgrader*.jar"/>
    <include name="hello*.jar"/>
</fileset>

However, these files are copied into the ${lib.dir}, i.e, the ${lib.dir} contains copies of core*.jar, fileset*.jar, etc. How do I delete these copied files?


Also, please note I can't use external libraries like ant-contrib.


Solution

  • Use a PatternSet to define the set of names. Then reference that PatternSet in any number of FileSets.

    <patternset id="module.patterns">
        <include name="core*.jar"/>
        <include name="fileset*.jar"/>
        <include name="upgrader*.jar"/>
        <include name="hello*.jar"/>
    </patternset>
    
    <fileset id="modules" dir="${modules.dir}" >
      <patternset refid="module.patterns"/>
    </fileset>
    

    UPDATE:

    Given your comment that you want only the original files, try this:

    <pathconvert pathsep="," property="flattened.modules" refid="modules">
        <mapper type="flatten" />
    </pathconvert>
    
    <filelist id="libmodules" dir="${lib.dir}" files="${flattened.modules}"/>