ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Diane Holt <>
Subject Re: short file name of the current build xml file
Date Fri, 21 Sep 2001 16:25:33 GMT
--- Chassande-Barrioz Sebastien <> wrote:
> I would like to know how it's possible to find the file name of the
> current build file. I found in the documentation that there is a
> file.ant property,

Actually, it's "ant.file".

> but this field gives the absolute path. And I would like set in a
> property the short name of the file: the name without the path and
> without the .xml extension. Does ant provide tools to format string ?

There's some string manipulation available in certain tasks, but it's not
generally available outside of those tasks. The only thing available to
you would be to either write a task or do it in a script. I felt like
writing a script :)  Here you go (change "projname" to the actual name of
your project)...

  <target name="getBasename">
    <script language="javascript"> <![CDATA[
      file = new File(projname.getProperty("ant.file"));
      basename = file.getName();
      if (basename.endsWith(".xml")) {
        pos = basename.indexOf('.');
        basename = basename.substring(0, pos);
      projname.setProperty("basename", basename) ;

  <target name="setBasename" depends="getBasename">
    <echo message="basename = ${basename}"/>



Terrorist Attacks on U.S. - How can you help?
Donate cash, emergency relief information

View raw message