如何编写ant脚本来检查给定字符串是文件还是目录

如何编写ant脚本来检查给定字符串是文件还是目录,ant,Ant,如何使用write ant脚本检查文件是文件还是目录??? 给定字符串“C:\test\application\Services\test” 我需要知道这个字符串 “C:\test\application\Services\test” 是一个文件或目录 我使用下面的脚本进行检查,看起来无法确定它是文件还是目录 <if> <available file="${sourceFile}" /> <then> <echo>

如何使用write ant脚本检查文件是文件还是目录???
给定字符串“C:\test\application\Services\test”

我需要知道这个字符串
“C:\test\application\Services\test”

是一个文件或目录

我使用下面的脚本进行检查,看起来无法确定它是文件还是目录

<if>
    <available file="${sourceFile}" />
    <then>
        <echo> It is a File ${sourceFile}</echo>
        <copyfile src="${sourceFile}" dest="${targetFile}" />
        <echo> Single file copied:  sourceFile = ${sourceFile}</echo>
    </then>
    <else>
        <if>
            <available file="${dir}" type="dir" />
            <then>
                <echo> It is a Directory:  ${sourceFile}</echo>
                <copy todir="${targetFile}">
                    <fileset dir="${sourceFile}" />
                </copy>
                <echo> Single dir copied:  sourceFile = ${sourceFile}</echo>
            </then>
        </if>
    </else>
</if>

它是一个文件${sourceFile}
已复制单个文件:sourceFile=${sourceFile}
它是一个目录:${sourceFile}
复制的单目录:sourceFile=${sourceFile}
如何使用ant完成此任务?
谢谢

我们不是标准ANT的一部分(需要第三方jar)

目标的有条件执行如下:

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

    <property name="sourceFile" location="C:\test\application\Services\Test"/>

    <available property="sourceFile.is.a.file" file="${sourceFile}" type="file"/>
    <available property="sourceFile.is.a.dir" file="${sourceFile}" type="dir"/>

    <target name="process" depends="process-file,process-dir"/>

    <target name="process-dir" if="sourceFile.is.a.dir">
        <echo message="${sourceFile} is a dir"/>
    </target>

    <target name="process-file" if="sourceFile.is.a.file">
        <echo message="${sourceFile} is a file"/>
    </target>

</project>

关键是,如果找到文件或目录,则available file=“…”/without type=“dir | file”将返回true。类型属性没有默认值“file”。