Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ANT select a file based on pattern, move to dest and rename

Tags:

ant

I'm trying to copy files under all the directory startting at the root folder that ends with _${env}.xml and strip the _${env} from the filename if found or copy the xml file whichever is present in the directory.I can't get this to work please help.(possibly i need a move and mapper to rename and I somehow can't weave them together.)

<target name="main">
    <copy todir="qa-wprelease"> 
        <fileset  dir="bin-debug" includes="**/*.xml"> 
            <or>
                <filename name="*_${env}.xml"/> 
                <filename name="*.xml" />
            </or>
        </fileset>
    </copy> 
</target>
like image 649
Priya Rammohan Avatar asked Dec 20 '22 19:12

Priya Rammohan


1 Answers

Check the manual of <copy> task -- <copy> can take a <mapper> as nested element, which can change your filenames during copy with a pattern. <mapper> has many types, with some of them you can even use javascript to change your filename.

So... Maybe you can do it this way (not tested so not sure if it works):

<copy todir="qa-wprelease" includeemptydirs="false">
    <fileset dir="bin-debug" includes="**/*.xml" />
    <globmapper from="*_${env}.xml" to="*.xml"/>
</copy>
like image 95
Dante WWWW Avatar answered Mar 07 '23 12:03

Dante WWWW