Showing posts with label ant. Show all posts
Showing posts with label ant. Show all posts

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?