Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

[ant] copy, creating directories as needed

 
Chris Reeves
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2676
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you taken a look at the mkdir task? It allows you to create directories.
 
Chris Reeves
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about using "mkdir"'s -p option?
will that help at all ?
 
timothy zimmerman
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is the unix mkdir command? I believe Ant's mkdir task behaves like mkdir -p by default.
 
Raj Birru
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Chris Reeves
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic