You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by "bmilbratz@outstart.com" <bm...@outstart.com> on 2009/01/19 18:54:59 UTC

problem: how to copy multiple directories in ant

Hi,

I have a well-defined problem I can easily solve via a shell script, but
want to know the ant-equivalent. This issue has come up on the ant user
mailing list before, but no answer surfaced. I've tried using various
combinations of fileset and dirset, but without success. Can someone
offer some insights?

The problem:
================
I have a directory structure like this:

  |-patches
  |---patch01
  |-----com
  |-------foo
  |---------classes
  |-----------bad
  |--------------Bad.class
  |-----------good
  |--------------Good.class
  |-----------ugly
  |---patch02
  |-----com
  |-------foo
  |---------classes
  |-----------bad
  |--------------Bad.class
  |-----------good
  |-----------ugly
  |--------------Ugly.class


I want to copy all the '.class' files in the ' patches/*/com'
directories to an output directory "staging_classes", i.e. so I end up
with the directory structure:
  |-staging_classes
  |-----com
  |-------foo
  |---------classes
  |-----------bad
  |--------------Bad.class (from patch02)
  |-----------good
  |--------------Good.class (from patch01)
  |-----------ugly
  |--------------Ugly.class (from patch02)


This shell script solves the problem:

#!/bin/sh
outdir=stagging_classes
patchdir=patches
cp -rf $patchdir/*/*/ $outdir

How do I solve this problem in ant? i've tried a few times using dirsets
and various combinations of copy,  but I end up with this (wrong)
directory structure:
  |-staging_classes
  |----patch01
  |---------com
  |-----------foo
  |-------------classes
  |----patch02
  |---------com
  |-----------foo
  |-------------classes

thanks in advance,

bill





---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: problem: how to copy multiple directories in ant

Posted by Dominique Devienne <dd...@gmail.com>.
>  |-----------bad
>  |--------------Bad.class (from patch02)

FWIW, fileset/dirset have an undefined order so it's difficult to
predict for sure that Bad.class will always come from patch02 rather
than patch01. Might work on one OS but not another. The new resource
collection may allow more control over the ordering though.

Somehow I think what you want may be possible with <copy> and a
mapper, but I could be wrong, and I've got other things to do than to
try it out ;-) --DD

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: problem: how to copy multiple directories in ant

Posted by "Rebhan, Gilbert" <Gi...@huk-coburg.de>.

-----Original Message-----
From: bmilbratz@outstart.com [mailto:bmilbratz@outstart.com]
Sent: Monday, January 19, 2009 6:55 PM
To: user@ant.apache.org
Subject: problem: how to copy multiple directories in ant

/*
Hi,

I have a well-defined problem I can easily solve via a shell script, but
want to know the ant-equivalent. This issue has come up on the ant user
mailing list before, but no answer surfaced. I've tried using various
combinations of fileset and dirset, but without success. Can someone
offer some insights?

The problem:
================
I have a directory structure like this:

  |-patches
  |---patch01
  |-----com
  |-------foo
  |---------classes
  |-----------bad
  |--------------Bad.class
  |-----------good
  |--------------Good.class
  |-----------ugly
  |---patch02
  |-----com
  |-------foo
  |---------classes
  |-----------bad
  |--------------Bad.class
  |-----------good
  |-----------ugly
  |--------------Ugly.class


I want to copy all the '.class' files in the ' patches/*/com'
directories to an output directory "staging_classes", i.e. so I end up
with the directory structure:
  |-staging_classes
  |-----com
  |-------foo
  |---------classes
  |-----------bad
  |--------------Bad.class (from patch02)
  |-----------good
  |--------------Good.class (from patch01)
  |-----------ugly
  |--------------Ugly.class (from patch02)

[...]

*/

<project name="bla" default="main" basedir=".">

<!-- // Taskdefs -->
<!-- Import AntContrib -->
<taskdef resource="net/sf/antcontrib/antlib.xml" />
<!-- Taskdefs // -->

<!-- // Properties -->
<property name="patchroot" value="C:/patches"/>
<property name="stagedir" value="C:/stagedir"/>
<!-- Properties // -->

<target name="main">
  <for param="patchdir">
    <dirset dir="${patchroot}" includes="**/patch*/**" />
    <sequential>
      <echo>Patchdir = @{patchdir}</echo>
      <copy todir="${stagedir}" overwrite="true" verbose="true">
        <fileset dir="@{patchdir}" includes="*/*.class" />
      </copy>
    </sequential>
  </for>
</target>

</project>


Regards, Gilbert

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org