wood burning stoves 2.0*
The moose likes Struts and the fly likes [ant] copy, creating directories as needed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "[ant] copy, creating directories as needed" Watch "[ant] copy, creating directories as needed" New topic
Author

[ant] copy, creating directories as needed

Chris Reeves
Ranch Hand

Joined: Apr 03, 2002
Posts: 95
I need to copy a set of files and directories to another location, but the directories don't exist in the new location. As such, I get an error that they don't exist. I need the copy process to copy files and directories recursively, creating directories as needed.
I have checked the task documentation, but I can't seem to come up with a simple way to do this.
Any suggestions?
Matthew Phillips
Ranch Hand

Joined: Mar 09, 2001
Posts: 2676
Have you taken a look at the mkdir task? It allows you to create directories.


Matthew Phillips
Chris Reeves
Ranch Hand

Joined: Apr 03, 2002
Posts: 95
Sure - I use mkdir all the time.
The problem is in copying a set of files and directories that I don't know the composition of - I want to pick them up and copy them without having to know what sub-directories exist.
timothy zimmerman
Ranch Hand

Joined: Jun 26, 2001
Posts: 149
Yes, if you use mkdir task to create the top level that you want to copy into the copy task should take care of the rest.
One thing you might do is create an init task that will create the top level directories and make this and other tasks which may need those directories depend on that init task.
timothy zimmerman
Ranch Hand

Joined: Jun 26, 2001
Posts: 149
You shouldn't have to know the directory structure beneath that which you are copying the copy task should handle that for you. Have I misunderstood something?
Raj Birru
Greenhorn

Joined: Jul 12, 2002
Posts: 24
How about using "mkdir"'s -p option?
will that help at all ?
timothy zimmerman
Ranch Hand

Joined: Jun 26, 2001
Posts: 149
That is the unix mkdir command? I believe Ant's mkdir task behaves like mkdir -p by default.
Raj Birru
Greenhorn

Joined: Jul 12, 2002
Posts: 24
Timothy, thats right -p option is unix mkdir option. I didn't know that Ant's mkdir is same as mkdir -p. Thanks for the info.
Chris Reeves
Ranch Hand

Joined: Apr 03, 2002
Posts: 95
I've tried using the copy task to copy files recursively into a root directory that exists (none of the subdirectories exist). It works perfectly.
Greg Ostravich
Ranch Hand

Joined: Jul 11, 2002
Posts: 112
In my code I have a dependency that creates the directories [ which it sounds like may not be necessary looking at these posts] and when I use a copy task it handles the rest recursively.
Here's my example:


Greg Ostravich - SCPJ2
Chris Reeves
Ranch Hand

Joined: Apr 03, 2002
Posts: 95
Greg, I create the directories for build in my prepare task too. I have another task that blows them away too - it's nice to get a clean start from time to time.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: [ant] copy, creating directories as needed