使用ANT检查多个文件是否存在 [英] Check multiple file exists or not using ANT

查看:26
本文介绍了使用ANT检查多个文件是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ANT 检查两个 jar 中文件集的计数.我无法检查是否存在相同模式的文件.

I am using ANT to check count for set of files in two jars. I am not able to check whether the files of same pattern exists or not.

例如我有 2 个文件,如/host/user/dir1/ABC1.txt 和/host/user/dir1/ABC2.txt.

for e.g. I have 2 files like /host/user/dir1/ABC1.txt and /host/user/dir1/ABC2.txt.

现在我想检查模式/host/user/dir1/ABC*"的文件是否存在??

now i want to check whether the file of pattern "/host/user/dir1/ABC*" present or not ??

我可以使用可用标签检查单个文件/host/user/dir1/ABC1.txt,但无法检查特定模式的文件.

I can check individual file /host/user/dir1/ABC1.txt, using available tag, but not able to check the files for specific pattern.

提前致谢.

对于单个文件,以下工作正常:

For individual file, following works fine:

<if>
    <available file="${client.classes.src.dir}/${class_to_be_search}.class"/>
    <then>
         <echo> File ${client.classes.src.dir}/${class_to_be_search}.class FOUND in src dir 

         </echo>
         <echo> Update property client.jar.packages.listOfInnerClass</echo>
    </then>
    <else>
         <echo> File ${client.classes.src.dir}/${class_to_be_search}.class NOT FOUND      in src dir.  
         </echo>
    </else>
</if>

但我想搜索多个文件:类似于:${dir.structure}/${class_to_be_search}$*.class

But i want to search for multiple files: something like : ${dir.structure}/${class_to_be_search}$*.class

推荐答案

if任务不是核心ANT的一部分.

The if task is not part of core ANT.

以下示例展示了如何使用 ANT 条件任务.您可以在文件集中使用任何您想要的模式.目标执行随后取决于file.found"属性的设置方式:

The following example shows how it can be done using the ANT condition task. You can use whatever pattern you want in the fileset. The target execution is subsequently conditional on how the "file.found" property has been set:

<project name="demo" default="run">

    <fileset id="classfiles" dir="build" includes="**/*.class"/>

    <condition property="file.found">
        <resourcecount refid="classfiles" when="greater" count="0"/>
    </condition>

    <target name="run" depends="found,notfound"/>

    <target name="found" if="file.found">
        <echo message="file found"/>
    </target>

    <target name="notfound" unless="file.found">
        <echo message="file not found"/>
    </target>

</project>

这篇关于使用ANT检查多个文件是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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