Ant copy and move directories recursively (without ant-contrib)
As a corollary to the recent post I made about trying to recursively moving or copying directories with Ant, this post shows you how to do so without the use of the third-party ant-contrib library. The trick is understanding Ant’s wildcard syntax used in the
Previously, I was trying to move a directory and all of its contents recursively to another directory using the following target
<target name="move.dirs"> <move todir="backups"> <fileset dir="." includes="*incremental*"/> </move> </target>
The result was a non-recursive copy of the first level of directories with ‘incremental’ in the directory name. The only way I could accomplish a deep copy or move at the time was to use ant-contrib’s
By modifying the wildcard syntax in my original target I am able get what I want.
<target name="move.dir"> <move todir="backups"> <fileset dir="." includes="**/*incremental*/"/> </move> </target>
So, the additional ‘**/’ at the beginning and a trailing ‘/’ at the end of the includes attribute value is all that is necessary. All directories (and their contents) with ‘incremental’ in the name will be moved to a directory called ‘backups/’. The same will work for the
Related Post: Move or copy a set of directories using Ant