Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2005

Tip: Looking for answers? Try searching our database.

Ant COPY task, want to copy the directory itself, not just its contents!

Thread view: 
dxd@ptc.com - 23 Jun 2005 17:32 GMT
I'm trying to use the ant copy task to copy a directory plus all its
contents and subdirectories to a new directory e.g.

Source directory is d:\temp\dir1

Target directory is c:\temp

I want to execute the copy task on d:\temp\dir1 and end up with
c:\temp\dir1

But what I get is the contents of d:\temp\dir1 going to c:\temp not the
directory itself.  Since there are many subdirectories in d:\temp I
don't want to just copy d:\temp to c:\temp.

I tried calling XCOPY from Ant but that behaves the same way.

Any suggestions?

Thanks

David
Andrew Thompson - 23 Jun 2005 18:02 GMT
> I'm trying to use the ant copy task to copy a directory plus all its
> contents and subdirectories to a new directory e.g.
[quoted text clipped - 5 lines]
> I want to execute the copy task on d:\temp\dir1 and end up with
> c:\temp\dir1

<not sure>
Make the target directory "c:\temp\dir1" or "c:\temp\dir1\" ?
</not sure>

I am pretty sure that ANT offers either
- automatic directory creation, or..
- the ability to make the directory specifically.

As an aside, your use of file/directory naming appears 'suspicious'.
1) If a drive is 'C' - I strongly recommend you refer to it
as 'C', rether than 'c'.  Remove possible errors before they are
encountered in some possibly fragile code.
2) A quick check of some of the ANT build.xml's on my
system, (largely obtained from folks that know what
they are doing), use the '/' consistently, and these
build files work just fine on Windows.  I suggest you
use forward slashes.

So 'c:\temp\dir1' -> 'C:/temp/dir1'

HTH

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

dxd@ptc.com - 23 Jun 2005 23:18 GMT
Thanks Andrew,

I guess that might work (I'm at home tonight I'll try it in the office
tomorrow) but trouble is, I don't want to have to parse the source
directory to extract the name of the last directory then append it onto
the target directory. I'm not even sure if you could do this in Ant but
even if you can (and of course I could embed Javascript to do it) it
would look a real mess.

In fact I simplified my real code in my post, so I'm not concerned
about backslash versus forward slash, I do handle this OK in the
script.

It looks like it's just a limitation of both <copy> and xcopy, but a
bit of a pain!

David

> > I'm trying to use the ant copy task to copy a directory plus all its
> > contents and subdirectories to a new directory e.g.
[quoted text clipped - 34 lines]
> http://www.1point1C.org/  Science & Technology
> http://www.LensEscapes.com/  Images that escape the mundane
dxd@ptc.com - 28 Jun 2005 12:09 GMT
This approach did work, but I ended up embedding javascipt (which I
didn't want to do, because I didn't want any dependency on additional
libraries) so that I could get the last name of the source folder and
construct the name of the target folder. Not very elegant!

David

> Thanks Andrew,
>
[quoted text clipped - 52 lines]
> > http://www.1point1C.org/  Science & Technology
> > http://www.LensEscapes.com/  Images that escape the mundane
Raymond DeCampo - 28 Jun 2005 14:51 GMT
Please do not top post on a thread where bottom posting has been the norm.

> This approach did work, but I ended up embedding javascipt (which I
> didn't want to do, because I didn't want any dependency on additional
[quoted text clipped - 50 lines]
>>>
>>>So 'c:\temp\dir1' -> 'C:/temp/dir1'

Did you try setting the context directory to be the parent directory of
the directory you want to copy and then include only the desired
directory via filters?  That is, in high level language, tell ANT to
recursively copy all files/directories named "dir1" from D:/temp to C:/temp?

Ray

Signature

XML is the programmer's duct tape.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.