You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by ar81 <ar...@free.fr> on 2006/03/21 23:55:37 UTC

Getting relative pathes in a for loop

Hi all,

When I write the following loop, I get absolute file pathes.

      <for param="file">
          <path>
             <fileset dir="${work.dir}" includes="**/*.xml"/>
          </path>
          <sequential>
             <echo message="File : @{file}" />
          </sequential>
       </for>

C:\Temp\dir1\file1.xml
C:\Temp\dir1\file2.xml
C:\Temp\dir1\file3.xml

where work.dir=C:\Temp\dir1

I'd like to get :
file1.xml
file2.xml
file3.xml

Does anybody know how to transform absolute pathes to relative pathes ?

Thanks

A. ROY


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


Re: Getting relative pathes in a for loop

Posted by Peter Reilly <pe...@gmail.com>.
I use propertyregex with the help of a macro:
  <!-- *********************************************
       Macro to set a property to the first
       group of a regexp applied on an input string.
       ********************************************** -->
  <macrodef name="regset1">
    <attribute name="regexp"/>
    <attribute name="input"/>
    <attribute name="property"/>
    <sequential>
      <ac:propertyregex override="yes"
                        property="@{property}"  input="@{input}"
                        regexp="@{regexp}" replace="\1"/>
    </sequential>
  </macrodef>

          <regset1 property="program" input="@{file}"
                  regexp=".*/([^\.]*)\.cpp"/>

In this case I am using the /dir/dir/dir/x.cpp name and
extracting the x as the program name.


On 3/21/06, Ivan Rambius Ivanov <ra...@yahoo.com> wrote:
>
> Hello,
>
> In your case you can use <basename> to get the name of
> the file. For more sophisticated operations on paths
> you may find useful <pathconvert> with nested
> <mapper>.
>
> Regards
> Ivan
>
> --- ar81 <ar...@free.fr> wrote:
>
> > Hi all,
> >
> > When I write the following loop, I get absolute file
> > pathes.
> >
> >       <for param="file">
> >           <path>
> >              <fileset dir="${work.dir}"
> > includes="**/*.xml"/>
> >           </path>
> >           <sequential>
> >              <echo message="File : @{file}" />
> >           </sequential>
> >        </for>
> >
> > C:\Temp\dir1\file1.xml
> > C:\Temp\dir1\file2.xml
> > C:\Temp\dir1\file3.xml
> >
> > where work.dir=C:\Temp\dir1
> >
> > I'd like to get :
> > file1.xml
> > file2.xml
> > file3.xml
> >
> > Does anybody know how to transform absolute pathes
> > to relative pathes ?
> >
> > Thanks
> >
> > A. ROY
> >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> > user-unsubscribe@ant.apache.org
> > For additional commands, e-mail:
> > user-help@ant.apache.org
> >
> >
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>

Re: Getting relative pathes in a for loop

Posted by "Ivan \"Rambius\" Ivanov" <ra...@yahoo.com>.
Hello,

In your case you can use <basename> to get the name of
the file. For more sophisticated operations on paths
you may find useful <pathconvert> with nested
<mapper>.

Regards
Ivan

--- ar81 <ar...@free.fr> wrote:

> Hi all,
> 
> When I write the following loop, I get absolute file
> pathes.
> 
>       <for param="file">
>           <path>
>              <fileset dir="${work.dir}"
> includes="**/*.xml"/>
>           </path>
>           <sequential>
>              <echo message="File : @{file}" />
>           </sequential>
>        </for>
> 
> C:\Temp\dir1\file1.xml
> C:\Temp\dir1\file2.xml
> C:\Temp\dir1\file3.xml
> 
> where work.dir=C:\Temp\dir1
> 
> I'd like to get :
> file1.xml
> file2.xml
> file3.xml
> 
> Does anybody know how to transform absolute pathes
> to relative pathes ?
> 
> Thanks
> 
> A. ROY
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@ant.apache.org
> For additional commands, e-mail:
> user-help@ant.apache.org
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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