tags:

views:

18

answers:

1

Hi there,

I am doing some ANT scripts just now and I am looking to copy a directory from one location to the other. However, after looking at "copy" and "copyDir" (which is deprecated) it seems that ANT (by default) only copies the content of one location to another, not the actual directory (and everything in it).

So, as an example I have the following:

./Foo/test.txt

And I apply the following piece of ANT :

 <copy todir="./build">
    <fileset dir="./Foo"/>
 </copy>

The result looks like this:

./build/test.txt

Whereas I would like it to be:

./build/Foo/test.txt

Hope that makes sense.

Thanks,

Stuart

A: 

To preserve the structure you would need to be copying the parent folder. There is a flatten option in the copy command, but it defaults to false. You can also make the directory structure you want, then copy at the file level straight into your fresh folder.

Here is the relevant line from the reference

Blockquote When a <fileset> is used to select files to copy, the todir attribute must be set. Files that are located under the base directory of the <fileset> will be copied to a directory under the destination directory matching the path relative to the base directory of the <fileset>, unless the flatten attribute is set to true.

The problem lies in that you are picking up the Foo folder, so you only get the files under it, you need to pick the folder above Foo to get the fileset where the ~/Foo/file.txt structure exists.

Mark Dickinson
Great, thanks for that.
sjwb
Did it help? any chance of some votes? ;-)
Mark Dickinson