Java Mailing List Archive

http://www.ant-tasks.com/

Apache Ant Archive

» Ant Users List
» Ant Developers List
Rename directories in Ant

Rename directories in Ant

2007-06-13       - By Qazwart
Reply:     1     2     3     4     5     6     7     8     9     10     >>  

What version of Ant are you using? You seem to take the hard way:

If you're using at least version 1.3, you can simply do this:

<move file="/tmp/myDir/test/hello/search"
    todir="/tmp/myDir/test/hello/search_"/>

If it's earlier than version 1.3:

<move todir="/tmp/myDir/test/hello/search_">
   <fileset dir="/tmp/myDir/test/hello/search"/>
</move>

No need to use a mapper or anything:

BTW, the problem you're running into is that regex is naturally
greedy, so it always takes the biggest chunk it can to make the
match. Since you can easily define the directory using simpler
globbing expressions, you could have use that. Or, you can use the
"Reluctant" qualifier which will only take the very first match it
can find:

This: <regexpmapper from="(.*?)(${oldValue})(.*)" to="\1${newValue}\3"
Instead of: <regexpmapper from="(.*)(${oldValue})(.*)" to="\1$
{newValue}\3"

See: http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/
Pattern.html for more information.

On Jun 13, 2007, at 3:31 AM, Cesar Martinez Izquierdo wrote:

> Hi, I'm trying to rename every "search" directory in a tree to
> "search_", but I'm not able to find the right way to do it.
>
> For example, if I have the files:
>
> /tmp/myDir/test/hello/search/Hello.html
> /tmp/myDir/test/hello/search/nice/lists/search/Greetings.html
> /tmp/myDir/test/hello/searchstrings/Hello.html
> /tmp/myDir/search/Regards.html
>
> I want to rename them to:
>
>
> /tmp/myDir/test/hello/search_/Hello.html
> /tmp/myDir/test/hello/search_/nice/lists/search_/Greetings.html
> /tmp/myDir/test/hello/searchstrings/Hello.html
> /tmp/myDir/search_/Regards.html
>
> I've read the docs and searched in Google, but I didn't find the
> solution.
>
> I have tried the following:
> -------------------------------
> <antcall target="renameFiles">
>   <param name="targetDir" value="/tmp/myDir" />
>   <param name="oldValue" value="/search"/>
>   <param name="newValue" value="/search_" />
> </antcall>
>  
> <target name="renameDirs"
>     description="Rename directories frin ${oldValue} to ${newValue}">
>   <move todir="${targetDir}" verbose="yes">
>     <fileset
>         dir="${targetDir}"
>         includes="**/*"/>
>     <regexpmapper from="(.*)(${oldValue})(.*)" to="\1${newValue}\3"
>         handledirsep="true"/>
>   </move>
> </target>
> -----------------------
>
> But I get the results:
> /tmp/myDir/test/hello/search_/Hello.html
> /tmp/myDir/test/hello/search_/nice/lists [empty dir]
> /tmp/myDir/test/hello/search/nice/lists/search_/Greetings.html
> /tmp/myDir/test/hello/search_strings/Hello.html
> /tmp/myDir/search/Regards.html
>
> which is not the result I expected.
> Is there a way to perform this task? If it's possible, it would be
> very
> useful to include it in the documentation, as I've found in Google
> several people trying to do it, but none of them found the solution.
>
> Regards,
>
> --
> C?sar Mart?nez Izquierdo
> Equipo de desarrollo gvSIG
> http://www.gvsig.gva.es
>
> IVER T.I.
> C/ Salamanca 50
> 46005 Valencia - Spain
> http://www.iver.es
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@(protected)
> For additional commands, e-mail: user-help@(protected)
>

David Weintraub
david@(protected)
qazwart@(protected)



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@(protected)
For additional commands, e-mail: user-help@(protected)


©2008 ant-tasks.com - Jax Systems, LLC, U.S.A.