ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Georg-Johann Lay <>
Subject Re: [ant] Determining relative paths resp. substring?
Date Sat, 17 Jan 2009 22:32:04 GMT
Georg-Johann Lay schrieb:
> Hi,
> can anyone assist me in solving this following quite trivial problem?
> Given a path A and the current directory B=. derermine B relative to A. 
> This is needed for prefixes in zipfileset.
> In the special case that I am after B is a subdirectory (of some level) 
> of A. So gettig the relative path B-A means that A and B look like this:
> A=<sting1>
> B=<sting1><string2>
> I wasted hours to figure out how this could be achieved... The regex 
> stuff is too complicated because dirs may contain special chars like 
> blanke, ., \, /, -, $ and even *.
> How can I easily remove the prexix A from B? I bet it is a one-liner.

Hallo again. Eventuelly the time was not wasted. I am using the 
following code. It is not exactly removing a prefix; it's a little bit more:

<macrodef name="set">
     <attribute name="property" />
     <attribute name="string" />
         <property name="@{property}" value="@{string}"/>

<tempfile property="prefix.file" />

<macrodef name="unprefix">
     <attribute name="property"/>
     <attribute name="prefix"/>
     <attribute name="string"/>
         <echo message=".string.suffix.@{property}=!!@{string}" 
file="${prefix.file}" />
         <replace file="${prefix.file}" token="=!!@{prefix}" value="=!!" />
         <replace file="${prefix.file}" token="\" value="/" />
         <replaceregexp file="${prefix.file}" match="//*"   replace="/" />
         <replaceregexp file="${prefix.file}" match="=!!/*" replace="=" />
         <property file="${prefix.file}" />
         <property name="@{property}" 
         <delete file="${prefix.file}" deleteonexit="true" />

Maybe someone finds is useful.

Grüß, Georg-Johann

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message