Apache Ant Tasks 简明教程

Apache Ant Tasks - BaseName

Description

Basename 任务确定指定文件/目录的基本名称,同时移除通过的后缀(如果已通过)。如果是文件的完整路径,则使用文件的名称。如果是目录路径,则使用最后一个目录的名称。

Basename task determines the base name of the specified file/directory while removing the suffix if passed. In case of full path of file, the name of the file is used. In case of directory path, the name of the last directory is used.

Properties

Sr.No

Attributes & Description

1

File The path to take the basename of. (Mandatory)

2

Property The name of the property to set. (Mandatory)

3

Suffix The suffix to remove from the resulting basename (specified either with or without the .). (Optional)

Example

Usage

使用以下内容创建 build.xml −

Create build.xml with the following content −

<?xml version="1.0"?>
<project name="TutorialPoint" default="info">
   <target name="info">
      <basename property="cmdname" file="D:/usr/local/application.exe"
         suffix=".exe"/>
      <echo message="${cmdname}"></echo>
   </target>
</project>

Output

在上述构建文件上运行 Ant 会生成以下输出:

Running Ant on the above build file produces the following output −

F:\tutorialspoint\ant>ant
Buildfile: F:\tutorialspoint\ant\build.xml

info:
   [echo] application

BUILD SUCCESSFUL
Total time: 0 seconds