Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Ant COPY task, want to copy the directory itself, not just its contents!

Reply
Thread Tools

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

 
 
dxd@ptc.com
Guest
Posts: n/a
 
      06-23-2005
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

 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      06-23-2005
On 23 Jun 2005 09:32:12 -0700, wrote:

> 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


<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

--
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
 
Reply With Quote
 
 
 
 
dxd@ptc.com
Guest
Posts: n/a
 
      06-23-2005

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


Andrew Thompson wrote:
> On 23 Jun 2005 09:32:12 -0700, wrote:
>
> > 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

>
> <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
>
> --
> 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


 
Reply With Quote
 
dxd@ptc.com
Guest
Posts: n/a
 
      06-28-2005
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

wrote:
> 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
>
>
> Andrew Thompson wrote:
> > On 23 Jun 2005 09:32:12 -0700, wrote:
> >
> > > 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

> >
> > <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
> >
> > --
> > 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


 
Reply With Quote
 
Raymond DeCampo
Guest
Posts: n/a
 
      06-28-2005
wrote:

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
> 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
>
> wrote:
>
>>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
>>
>>
>>Andrew Thompson wrote:
>>
>>>On 23 Jun 2005 09:32:12 -0700, wrote:
>>>
>>>
>>>>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
>>>
>>><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'
>>>


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

--
XML is the programmer's duct tape.
 
Reply With Quote
 
HeidelbergMan HeidelbergMan is offline
Junior Member
Join Date: Jul 2007
Posts: 2
 
      11-13-2010
Javascript? Really?!

This is an olde post but I found it when looking for a quick answer so here's a solution that works for me to do the "deep copy". Similar solution works for delete etc.


<target name="copySQLFiles">
<mkdir dir="${master.build.source.sql.dir}"/>
<copy todir="${master.build.source.sql.dir}">
<fileset dir="${master.source.sql.dir}" includes="**/*.sql" />
</copy>
</target>

You can of course start with use constant dirs instead of my ${} vars, say "C:/svn/myproductrepo" or leave out the .sql to copy all.
 
Reply With Quote
 
Diplomat Diplomat is offline
Junior Member
Join Date: Jan 2011
Posts: 1
 
      01-12-2011
To copy directory with all its content just add a trailing slash, just like:
<copy todir="c:/temp/">
<fileset dir="c:/temp/dir1/"/>
</copy>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Its a bird, its a plane, its.. um, an Attribute based System? thunk Ruby 14 04-03-2010 10:08 AM
Its a bird, its a plane, its.. um, an Attribute based System? thunk Ruby 0 04-01-2010 10:25 PM
Its a bird, its a plane, no ummm, its a Ruide thunk Ruby 1 03-30-2010 11:10 AM
In Ant how do you exclude a directory from copy or zip elektrophyte Java 6 10-02-2005 03:31 PM
trouble with Hibernate and Ant (probably just Ant) john martin Java 2 04-07-2005 09:27 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57