Avatar of laneway
laneway
Flag for Canada asked on

How do I quickly copy a directory using Apache Ant?

I am trying to duplicate a directory using apache ant and the copy task. When I use my OS to duplicate the directory, it takes about 30 seconds. When I use the ant copy task (as shown below) it takes 4 minutes and 30 seconds! Is there a faster way?
<target name="copy-dir">			
	<copy todir="./newdir">
		<fileset dir="./copyme"/>
	</copy>
</target>

Open in new window

ProgrammingEditors IDEs

Avatar of undefined
Last Comment
laneway

8/22/2022 - Mon
girionis

It shouldn't take so long. Do you only copy the files or you execute other tasks as well? If all alse fails you can try to exec task, which calls an external process. So you could call the copy command and copy the files using the native processes.

http://ant.apache.org/manual/CoreTasks/exec.html
laneway

ASKER
I am not doing anything else, the wait time comes from here. It seems to be copying the contents of the directory file by file rather than by the whole directory.

Is it possible that it is excluding some files or applying a pattern without me knowing it?

Interestingly if I use the old copydir task, it takes 2 minutes and 30 seconds instead of 4 minutes and 30 seconds...

I don't get it.
girionis

I am not sure what is going on behind the hood. Maybe it has to do other things before it can copy all the files. And it's possible that it's using Java to do it, so it has to load up all the necessary classes and then do a copy. Have you tried using the exec task?
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
laneway

ASKER
I need this script to be cross platform. MacOs, Windows, Linux. Will the exec task work in that case?
ASKER CERTIFIED SOLUTION
girionis

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
laneway

ASKER
I am convinced that the exec task method will work, though it is not as elegant as I had hoped. I suspect that either ANT is just slow or there is some other non-obvious reason why it is behaving the way it does on my system.