Ant脚本分割文件名和扩展到2个独立的属性 [英] ANT Script Split file name and extension into 2 separate properties

查看:426
本文介绍了Ant脚本分割文件名和扩展到2个独立的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有了说10文件,扩展的文件集。我需要再采取这种并获得文件名和扩展到2个独立的属性/变量,但不知道如何。我之所以要做到这一点作为一个文件开始了在Unix作为XB12345.FILE,我需要移动到一个I / 5系统的文件名作为XB12345.FILE和成员为FILE.MBR。大多数的文件不具有一致的扩展,将仅在运行时是已知的。任何帮助将是AP preciated。

I have a fileset that has say 10 files with extensions. I need to then take this and get the filename and extension into 2 separate properties/variables but not sure how. The reason I need to do this as a file starts out on Unix as XB12345.FILE which I need to move to an I/5 system with the file name as XB12345.FILE and the member as FILE.MBR. Most of the files do not have a consistent extension and will only be known at run time. Any help would be appreciated.

推荐答案

这听起来像是对的蚂蚁的Contrib 任务。

This sounds like a job for the Ant-Contrib tasks.

蚂蚁的Contrib任务已经存在了很长一段时间,是相当常见的蚂蚁项目中看到的。该 PropertyRegex ​​任务将做你想做的。事实上,甚至有一个对于能够处理回路任务。

The Ant-Contrib tasks have been around for a long time and are quite common to see in Ant projects. The PropertyRegex task will do what you want. In fact, there's even a For task that can handle loops.

< PropertyRegEx> 任务将是这个样子:

<propertyregex property="base.name"
    input="file.name"
    regexp="(.*)\.(.*)"
    select="\1"/>

<propertyregex property="suffix.name"
    input="file.name"
    regexp="(.*)\.(.*)"
    select="\2"/>

安装的Ant任务的Contrib是相当容易的,如果您按照下列步骤操作:

Installing the Ant-Contrib tasks is fairly easy if you follow these steps:


  • 下载<一个href=\"http://sourceforge.net/projects/ant-contrib/files/ant-contrib/1.0b3/ant-contrib-1.0b3-bin.tar.gz/download\"相对=nofollow>蚂蚁的contrib-1.0b3.jar 。

  • 创建在项目的根目录下名为的antlib / AC 目录。

  • 蚂蚁的contrib-1.0b3.jar文件中的的antlib / ac`目录。

  • 添加任务定义。

  • Download the ant-contrib-1.0b3.jar.
  • Create a directory in the root of your project called antlib/ac.
  • Put the ant-contrib-1.0b3.jar file in theantlib/ac` directory.
  • Add the task definition.

这样的:

<taskdef resource="net/sf/antcontrib/antlib.xml">
    <classpath>
        <fileset dir="${basedir}/antlib/ac"/>
    <classpath>
</taskdef>

如果你使用版本控制系统,检查蚂蚁的contrib-1.0b3.jar文件到该项目的版本控制系统。现在,当有人需要做一个构建,他们检出的项目,和Ant任务的Contrib已经定义和Ant-JAR的Contrib是存在的。没有必要为开发者安装Ant-和Contrib.to您的构建只是工作。

If you use a version control system, check in the ant-contrib-1.0b3.jar file into your version control system for the project. Now, when someone needs to do a build, they checkout your project, and the Ant Contrib tasks are already defined and the Ant-Contrib jar is there. There's no need for the developer to install Ant-Contrib. Your build just works.

这篇关于Ant脚本分割文件名和扩展到2个独立的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆