You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Laszlo Szabo <la...@googlemail.com> on 2007/08/08 15:18:41 UTC

Copying a subdirectory hierarchy containing variable intermediate subdirectory names

I'm trying to copy a subdirectory and its contents when it is separated from
the root directory by a couple of directories that are machine generated and
therefore have variable names.

For example in the following directory structure:
C:\BUILDS\Proj1_Code\devbuild\385633b5\f0e5959c\ejbModule

The 'root' directory for the build is C:\BUILDS\Proj1_Code\devbuild
The generated directories are 385633b5 and f0e5959c
The directory that I want to copy is ejbModule.

Is there an easy way to do this? The following copies everything below the
root which is not what I want (I only want ejbModule and its contents).

<copy todir="${build.dir}/test" >
                        <fileset dir="C:/BUILDS/Proj1_Code/devbuild">
                           <include name="**/ejbModule/**"/>
                        </fileset>

Re: Copying a subdirectory hierarchy containing variable intermediate subdirectory names

Posted by Steve Loughran <st...@apache.org>.
Laszlo Szabo wrote:
> I'm trying to copy a subdirectory and its contents when it is separated from
> the root directory by a couple of directories that are machine generated and
> therefore have variable names.
> 
> For example in the following directory structure:
> C:\BUILDS\Proj1_Code\devbuild\385633b5\f0e5959c\ejbModule
> 
> The 'root' directory for the build is C:\BUILDS\Proj1_Code\devbuild
> The generated directories are 385633b5 and f0e5959c
> The directory that I want to copy is ejbModule.
> 
> Is there an easy way to do this? The following copies everything below the
> root which is not what I want (I only want ejbModule and its contents).
> 
> <copy todir="${build.dir}/test" >
>                         <fileset dir="C:/BUILDS/Proj1_Code/devbuild">
>                            <include name="**/ejbModule/**"/>
>                         </fileset>
> 

Ok, so the problem is you want to strip out the machine generated 
directories?

For this you can use a mapper in the copy, that provides rules as how to 
rename things. I fear the mapper in question is the <regexp> mapper, 
which means you get a chance to work out the regular expression needed 
do to the mapping; something that matches on (and discards) the machine 
directories, but maps down everything below the ejbmodule.

Having a quick look at the mappers manual page, I think it would be 
something like this:

  <copy todir="${build.dir}/test" >
       <fileset dir="C:/BUILDS/Proj1_Code/devbuild">
           <include name="**/ejbModule/**"/>
        </fileset>
     <regexpmapper handledirsep="true"
       from="^(.*)/ejbModule/(.*)$$&" to="ejbModule/\2"/>
</copy>

But be warned, I rarely use this mapper, and am very ignorant. I'd do 
lots of -verbose runs to get it right

Let us know how it works, and we can add a new example for the documentation

-steve

-- 
Steve Loughran                  http://www.1060.org/blogxter/publish/5
Author: Ant in Action           http://antbook.org/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Copying a subdirectory hierarchy containing variable intermediate subdirectory names

Posted by Laszlo Szabo <la...@googlemail.com>.
Thanks Steve - it worked! (There was just a small typo with the & but after
removing it I got exactly what I required. Thanks again.

On 08/08/2007, Laszlo Szabo <la...@googlemail.com> wrote:
>
> I'm trying to copy a subdirectory and its contents when it is separated
> from the root directory by a couple of directories that are machine
> generated and therefore have variable names.
>
> For example in the following directory structure:
> C:\BUILDS\Proj1_Code\devbuild\385633b5\f0e5959c\ejbModule
>
> The 'root' directory for the build is C:\BUILDS\Proj1_Code\devbuild
> The generated directories are 385633b5 and f0e5959c
> The directory that I want to copy is ejbModule.
>
> Is there an easy way to do this? The following copies everything below the
> root which is not what I want (I only want ejbModule and its contents).
>
> <copy todir="${build.dir}/test" >
>                         <fileset dir="C:/BUILDS/Proj1_Code/devbuild">
>                            <include name="**/ejbModule/**"/>
>                         </fileset>
>
>
>
>