Copying Directories Recursively using Ant

E

Eric Bresie

Okay..I'm sure this is probably a simple newbie thing in ant, but...

I have a directory structure like the following:

base
base/src
base/data
base/distr
base/lib
base/lib/one
base/lib/two
base/lib/two/one
base/lib/two/two

With each directory having files contained in it.

In the base directory I have the build.xml file.

What is the proper way to have the data, lib, lib/one, lib/two,
lib/two/one, and lib/two/two directories and all the files contained
within them and have them all copied into distr in subdirectories
contained underneath (distr/data, distr/lib, distr/lib/one, etc).
Also want to exclude the src and the distr directory itself.

What is the proper way to do this?

I thought it would be something simple like:

<copy todir="distr">
<fileset dir="lib"/>
</copy>

But when I tried something similar, it took all the files in the lib
directory and copied them into the distr, it did not copy the lib
directory into the distr directory.

Anyone got a simple solution?

Eric
 
R

Ryan Stewart

Eric Bresie said:
Okay..I'm sure this is probably a simple newbie thing in ant, but...

I have a directory structure like the following:

base
base/src
base/data
base/distr
base/lib
base/lib/one
base/lib/two
base/lib/two/one
base/lib/two/two

With each directory having files contained in it.

In the base directory I have the build.xml file.

What is the proper way to have the data, lib, lib/one, lib/two,
lib/two/one, and lib/two/two directories and all the files contained
within them and have them all copied into distr in subdirectories
contained underneath (distr/data, distr/lib, distr/lib/one, etc).
Also want to exclude the src and the distr directory itself.

What is the proper way to do this?

I thought it would be something simple like:

<copy todir="distr">
<fileset dir="lib"/>
</copy>

But when I tried something similar, it took all the files in the lib
directory and copied them into the distr, it did not copy the lib
directory into the distr directory.

Anyone got a simple solution?

Eric

New to Ant myself. There's probably a better way, but this should do what
you want:
<copy todir="distr">
<fileset dir=".">
<include name="*" />
<exclude name="distr" />
<exclude name="src" />
<include name="data/**/*" />
<include name="lib/**/*" />
</fileset>
</copy>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top