ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dominique Devienne" <>
Subject RE: truncating a directory
Date Tue, 28 Sep 2004 03:47:31 GMT
> > -----Urspr√ľngliche Nachricht-----
> > Von: Greg Irvine []
> > I wish to move the contents of a number of directories to a single
> > directory, using a wildcard based set.  E.g. move build/*/** test/
> >
> > i.e.  Starting with:
> > build/
> > 	dirA/
> > 		subDirA/
> >
> > 	dirB/
> > 		subDirB/
> >
> >
> > Ending with:
> > test/
> > 	subDirA/
> >
> > 	subDirB/
> >

To emulate your 'move build/*/** test/' while stripping the * part,
the most logical would be either a nested <mapper>, as Jan suggested,
or something like:

  <move todir="test">
    <dirset dir="build" includes="dir*" />

Which would select dirA and dirB and use the default patternset of
**/*. If you wanted to use an explicit patternset, we'd need need
a new <multifileset> datatype, that accepts a <dirset> instead of
just a single 'dir' attribute.

Needless to say, all of the above isn't possible now. Many tasks
accept multiple filesets explicitly, and deal with them with an
explicit iteration in the task's code, but one's still forced to
list the filesets explicitly, instead of having them dynamically
generated to account for your use case.

That said, it sounds like you could use Ant-Contrib's excellent
<ac:for> task iterating over a path for example. And for once,
instead of pseudo-code, here's a concrete example:

D:\org_apache\antx>D:\com_lgc\cycle9\buildtools\ant\bin\ant -f movedirs.xml suite
Buildfile: movedirs.xml

    [mkdir] Created dir: D:\org_apache\antx\build\dirA\subDir1
    [mkdir] Created dir: D:\org_apache\antx\build\dirB\subDir1
    [mkdir] Created dir: D:\org_apache\antx\build\dirB\subDir2

     [move] Moving 1 files to D:\org_apache\antx\test
     [move] Moving 2 files to D:\org_apache\antx\test

   [delete] Deleting directory D:\org_apache\antx\build
     [echo] Move succeeded ;-)


Total time: 1 second
D:\org_apache\antx>type movedirs.xml
<?xml version="1.0" encoding="UTF-8"?>
  <target name="setUp">
    <mkdir dir="build/dirA/subDir1" />
    <echo file="build/dirA/subDir1/Alpha">Alpha</echo>

    <mkdir dir="build/dirB/subDir1" />
    <echo file="build/dirB/subDir1/Beta">Beta</echo>

    <mkdir dir="build/dirB/subDir2" />
    <echo file="build/dirB/subDir2/Gamma">Gamma</echo>

  <target name="tearDown">
    <condition property="OK">
        <available file="test/subDir1/Alpha" />
        <available file="test/subDir1/Beta" />
        <available file="test/subDir2/Gamma" />
    <delete dir="build" />
    <fail unless="OK">Move failed :-O</fail>
    <echo>Move succeeded ;-)</echo>

  <target name="testMoveDirs" depends="setUp">
    <mkdir dir="test" />
    <ac:for param="dir" xmlns:ac="antlib:net.sf.antcontrib">
      <path><dirset dir="build" includes="dir*" /></path>
        <move todir="test">
          <fileset dir="@{dir}" />

  <target name="suite" depends="testMoveDirs, tearDown" />

This works, and isn't even that bad looking, but I still think
we need a better way to specify files (or zip entries) that works
without having to hand code always the same boilerplate code in
the Java code. We'll get there eventually ;-) --DD

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message