Basename

Description

Task to determine the basename of a specified file, optionally minus a specified suffix.

When this task executes, it will set the specified property to the value of the last path element of the specified file. If file is a directory, the basename will be the last directory element. If file is a full-path, relative-path, or simple filename, the basename will be the simple file name, without any directory elements.

Parameters

Attribute Description Required
file The path to take the basename of. Yes
property The name of the property to set. Yes
suffix The suffix to remove from the resulting basename (specified either with or without the .). No

Examples

Set jar.filename to myjar.jar, if lib.jarfile is defined as either a full-path filename (eg., /usr/local/lib/myjar.jar), a relative-path filename (eg., lib/myjar.jar), or a simple filename (eg., myjar.jar).

<basename property="jar.filename" file="${lib.jarfile}"/>

Set cmdname to foo.

<basename property="cmdname" file="D:/usr/local/foo.exe"
          suffix=".exe"/>

Set temp.dirname to the last directory element of the path defined for the TEMP environment variable.

<property environment="env"/>
<basename property="temp.dirname" file="${env.TEMP}"/>