You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by T E Schmitz <ma...@numerixtechnology.de> on 2004/04/01 23:50:00 UTC

Re: Retrieving a list of directory names from fileset without the fully qualified path


This is just what I've been trying to figure the last few days!

Yours was the *nix version , here's the Windoze version for the regexp:

<propertyregex property="arg" global="true" override="true"
       input="K:\usr\dir\lib\bla.java"
       regexp="[a-zA-Z]:\\([^\\\s]+\\)+"
       replace=""
       defaultValue="failed" />


Now all I need to find out is how to do this as a global replacement on 
a string of semicolon-separated paths. Would it be possible to replace 
the semicolon with a newline?


Thanks for posting your finding.

Regards,

Tarlika Elisabeth Schmitz

Daniels, Doug wrote:

> I figured out how to convert a string of fully qualified directory names (or
> filenames for that matter) into just the directory name. The regular
> expression is '/([^/\s]+/)+' and here is an example ant blurb for anyone's
> future reference:
> 
> 
> 
>    <dirset id="homeDirs" dir="/tmp/${user.name}" includes="*"/>
> 
>    <pathconvert pathsep=" -s " refid="homeDirs" property="arguments"/>
> 
> <!-- This regular expression will match a fully qualified directory path(s)
> and leave you with just the directory name.
>      For example:
>      /abc/def/dir will be converted to dir
> -->
>    <propertyregex property="arguments" global="true" override="true"
>       input="${arguments}"
>       regexp="/([^/\s]+/)+"
>       replace=""
>       defaultValue="failed" />
> 
>    <!-- need starting -s so that all elements in the converted path have a
> -s prepending them -->
>    <echo>ARGUMENTS: -s ${arguments}</echo>
> 
> 
> 
> 
> ~ Doug Daniels
> 
> 
> -----Original Message-----
> From: Daniels, Doug 
> Sent: Thursday, April 01, 2004 11:54 AM
> To: 'Ant Users List'
> Subject: Retrieving a list of directory names from fileset without the
> ful ly qualified path
> 
> 
> Hi everyone, I'm not sure this is the place to ask but I'm looking for a
> regular expression that will convert an argument string that contains a list
> of directories with fully qualified paths and I want to strip this down to
> just the names of the directories without the rest of the path:
> 
> for example my string looks like this:
> 
> "-s /a/b/c -s /d/e/f" and I want to convert it to:
> "-s c -s f"
> 
> Here is my test code, I'm using the ant-contrib library for the
> <propertyregex> http://ant-contrib.sourceforge.net/, so point the libpath
> property to where your ant-contrib jar is:
> 
> 
> <project name="test" default="main">
> 
> <target name="main">
> 
> <taskdef resource="net/sf/antcontrib/antcontrib.properties">
>   <classpath>
>     <pathelement location="${libpath}/ant-contrib-0.3.jar"/>
>   </classpath>
> </taskdef>
> 
>    <dirset id="homeDirs" dir="${user.home}" includes="*"/>
> 
>    <pathconvert pathsep=" -s " refid="homeDirs" property="arguments"/>
> 
>    <propertyregex property="arguments" global="true" override="true"
>       input="${arguments}"
>       regexp="(/[\w\.]+/*)+(\s)"
>       replace="\1"
>       defaultValue="failed" />
>    
>    <echo>ARGUMENTS: ${arguments}</echo>
> 
> 
> </target>
> 
> 
> 
> </project>
> 
> ~ Doug Daniels
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 

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