【问题标题】:Is there any way to match file with number in its name in apache Ant build.xml有没有办法在 apache Ant build.xml 中匹配文件名称中的数字
【发布时间】:2019-05-27 04:07:17
【问题描述】:

我正在尝试匹配名称中包含数字的文件。看起来 Ant 只支持 * ? c 这些字符用于正则表达式。任何人都尝试过 ANT 正则表达式。 我想匹配名称为 TEST-3000-6564345.zip 的文件

<target name="demo">
    <mkdir dir="/dem"/>
    <unzip dest="src/main/resources/dem">
        <fileset dir="src/main/resources">
            <filename regex=".*[0-9]\d.*"/>
        </fileset>
    </unzip>
</target>

【问题讨论】:

    标签: java ant devops build-tools


    【解决方案1】:

    您可以使用正则表达式,但普通模式集不支持它们。相反,您需要使用选择器,例如 <filename>:

    <fileset dir="${files.root}">
        <filename regex=".*\d.*"/>
    </fileset>
    

    【讨论】:

    • java.util.zip.ZipException: 存档不是 ZIP 存档
    • 首先,\d 一个数字,所以[0-9]\d 试图匹配两个连续的数字。其次,如果您尝试匹配 zip 文件,您可能应该使用regex=".*\d.*\.zip"。该错误告诉您您的文件集匹配的文件不是 zip 文件。
    猜你喜欢
    • 2011-07-11
    • 2012-02-06
    • 1970-01-01
    • 2011-02-12
    • 2022-11-22
    • 2010-09-08
    • 2012-03-19
    • 2021-11-09
    • 2014-07-27
    相关资源
    最近更新 更多