2

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.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Amil
  • 609
  • 1
  • 5
  • 12

1 Answers1

3

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}"/> 
satur9nine
  • 13,927
  • 5
  • 80
  • 123
  • Assuming the next step would be to create a fileset in ${lib.dir} which matches the module.patterns patternset, this does not work. This is because my ${lib.dir} contains other core*.jar files that are not present in ${modules.dir} (and were not copied over) and I do not want to delete these also. – Amil Jan 11 '13 at 22:49
  • This answer might help too: http://stackoverflow.com/questions/13290555/ant-how-to-delete-files-that-are-not-present-in-another-directory – satur9nine Jan 17 '13 at 00:43