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: Easy Question: Rename a Directory
Date Wed, 21 Jul 2004 05:51:26 GMT
> > Is there an easy way to rename a directory that doesn't 
> have a performance
> > drain?  The Ant documentation states that the "<Rename>" 
> task has been
> > deprecated and to use "<Move>" instead.  However, all the 
> examples I've
> > seen with the "<Move>" task involve moving all the files and
> > sub-directories to the new directory and then deleting the 
> old directory:
> > 
> > <move todir="${temp.dir}/newname" includeEmptyDirs="true"
> > overwrite="true">
> >          <fileset dir="${temp.dir}/oldname"/>
> > </move>
> > 
> > This is not an acceptable solution.  All I want to do is re-name a
> > directory; I don't want to "move" any of its contents.  
> Does anyone have
> > another solution?
> 
> I think the only solution is to use a <script>, using JavaScript for
> example, that calls java.io.File.renameTo(). Still portable 
> because Java
> based, but a PITA because you need bsf.jar and rhino.jar (or 
> another JAR if
> you use another Java-based scripting language like BeanShell 
> or Jyhton or
> Groovy), and it doesn't look very Ant'ish. --DD


If you gave us the implementation, why not using Java itself? :-)

import java.io.File;
public class Rename {
    File from;
    File to;
    public void setFrom(File f) { from = f; }
    public void setTo(File f)   { to = f; }    
    public void execute() {
        from.renameTo(to);
    }
}


just compilation and a taskdef ...


Jan

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