Check multiple file exists or not using ANT

有些话、适合烂在心里 提交于 2020-01-15 06:59:26

问题


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.

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

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

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

thanks in advance.

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>

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


回答1:


The if task is not part of core ANT.

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>


来源:https://stackoverflow.com/questions/15698694/check-multiple-file-exists-or-not-using-ant

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!