Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ant copy with many mappers problem

Tags:

ant

I am want to copy all directory to another directory but also I must rename one file. I am trying this:

<copy todir="destDir" enablemultiplemappings="true">
  <fileset dir="sourceDir"/>
  <compositemapper>
    <identitymapper />
    <globmapper from="oldFileName" to="newFileName"/>
  </compositemapper>
</copy>

But this task copy all files, and than copy renamed file. And in destDir directory I have two files: destDir\oldFileName and destDir\newFileName. But I need only destDir\newFileName. Can someone help me with this?

EDITED: I need to copy all files form sourceDir to destDir, and rename only file with name "oldFileName".


1 Answers

Set enablemultiplemappings="false", and swap the order of your mappers:

<copy todir="destDir">
  <fileset dir="sourceDir" />
  <compositemapper>
    <globmapper from="oldFileName" to="newFileName" />
    <identitymapper />
  </compositemapper>
</copy>

Without multiple mappings enabled the first mapping that produces a filename 'wins'. So for the files needing a rename, the glob will apply. For all other files the identity mapper will name them as-is.

like image 84
martin clayton Avatar answered Mar 22 '26 15:03

martin clayton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!