Thursday, November 29, 2007

Copy directory structure using ANT

Here is a simple way to copy a complex directory structure to a new location.

May a times we would have faced this kind of requirement. A complex directory system with lot of files in it. And you want to copy only the directory structure not any files. If you are familiar with Apache ANT, there is a simple way to do this.

<project name="COPY" default="copy.only.dir" basedir=".">

<property name="source.dir" value="<sourceDir>"/>
<property name=" dest.dir" value="destinationDir"/>

<target name="copy.only.dir" depends="">
<copy todir="${dest.dir}">
<fileset dir="${ source.dir}">
<type type="dir"/>
</fileset>
</copy>
</target>

</project>

Save this XML to build.xml , change the source and destination directories and run ANT (from command prompt just type ant. This should be done from the directory where you have saved the build.xml)

Simple, but useful. Isn't it?

2 comments:

Anonymous said...

Hello. This post is likeable, and your blog is very interesting, congratulations :-). I will add in my blogroll =). If possible gives a last there on my blog, it is about the Wireless, I hope you enjoy. The address is http://wireless-brasil.blogspot.com. A hug.

NM said...

Simple, useful and completely self explanatory - Perfect! Thanks for putting this core Ant usage out here for us.