Reputation: 23345
Let's say I have a directory structure like this:
Using ant, I would like to rename all sub-directories under animals
called details
to now be named new
. So the result would be this:
I've tried something like this:
<move tofile="new">
<path id="directories.to.rename">
<dirset dir="animals">
<include name="**/details"/>
</dirset>
</path>
</move>
But get this error:
Cannot concatenate multiple files into a single file.
Upvotes: 1
Views: 1396
Reputation: 78105
You can carry out the rename you describe by means of a mapper. For example:
<move todir="animals">
<dirset dir="animals" includes="**/details" />
<globmapper from="*/details" to="*/new"/>
</move>
(There's a similar example at the end of the move
task docs.)
The error you saw arose because you've mixed the single-file mode of the move task (tofile) with multiple-file mode.
There's no need to nest the dirset
in a path
as the move
task accepts any file-based resource collection, including dirset
.
Upvotes: 3
Reputation: 28029
Use Ant-Contrib's for
task and propertyregex
task.
<target name="test">
<for param="detailsDir">
<dirset dir="animals">
<include name="**/details"/>
</dirset>
<sequential>
<propertyregex property="output.dir" input="@{detailsDir}" regexp="(.*)/details" replace="\1" />
<move file="@{detailsDir}" toFile="${output.dir}/new" />
</sequential>
</for>
</target>
Upvotes: 1