ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jan.Mate...@rzf.fin-nrw.de
Subject AW: Search for file in parent directories
Date Tue, 08 Jul 2003 17:11:17 GMT
He, he

a very quick hack, but works (but without any exception handling):



<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="test" basedir="." default="main">
    <target name="main">
        <property name="file" value="boot.ini"/>
        <property name="startdir" value="C:/tmp/anttests/search"/>

        <script language="javascript"> <![CDATA[
            // import statements
            importClass(java.io.File);

            file = project.getProperty("file");
            dir  = project.getProperty("startdir");
            dirf = new File(dir);
            f = new File(dir, file);

            while (!f.exists()) {
                dirf = new File(dirf.getParent());
                f = new File(dirf, file);
            }

            project.setProperty("location", f.getAbsolutePath());
        ]]></script>

        <echo>${file} found in ${location}</echo>
    </target>
</project>



Maybe you want to start here...


Jan



> -----Urspr√ľngliche Nachricht-----
> Von: Igor Bukanov [mailto:igor@fastmail.fm]
> Gesendet am: Dienstag, 8. Juli 2003 19:00
> An: user@ant.apache.org
> Betreff: Search for file in parent directories
> 
> Hi!
> 
> I would like to search for the given file name in the given 
> directory or 
> one of its parents and set a property to found location. 
> Something like 
> ant -find <name> does. Are there any better way to do it then 
> use when 
> searching for a.txt:
> 
> <avaialble property="found-path"
>   file="a.txt" value="a.txt"/>
> <avaialble property="found-path"
>   file="../a.txt" value="../a.txt"/>
> <avaialble property="found-path"
>   file="../../a.txt" value="../../a.txt"/>
> <avaialble property="found-path"
>   file="../../../a.txt" value="../../../a.txt"/>
> etc.
> 
> 
> Although it works if there is single a.txt in searched parent 
> directories, but when there several a.txt, then trouble 
> starts. First a 
> warning will be produced about changing of property value, 
> and second, 
> it will set found-path to the outemost a.txt. I can fix the later by 
> reversing <available> order, but then I would depend on deprecated 
> bahaviour.
> 
> Any better ways to do it?
> 
> Regards, Igor
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message