难道我有办法来检查蚂蚁目录(不是文件)的存在? [英] Do I have a way to check the existence of a directory in Ant (not a file)?

查看:127
本文介绍了难道我有办法来检查蚂蚁目录(不是文件)的存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何检查文件夹的使用Ant的存在?

How do I check for the existence of a folder using Ant?

我们可以检查文件是否存在,但我们可以做同样的文件夹呢?

We can check the existence of a file, but can we do the same for a folder as well?

推荐答案

您使用可用任务同类型设置为目录。

You use the available task with type set to "dir".

例如:

<available file="${dir}" type="dir"/>

做条件处理的标准方法是与条件任务。在下面的例子中,如果该目录存在,而运行doBar会响应消息运行doFoo会响应消息的除非的目录存在。

The standard way to do conditional processing is with the condition task. In the example below, running doFoo will echo a message if the directory exists, whereas running doBar will echo a message unless the directory exists.

dir.check 的由两个doFoo和doBar要求的目标,它设置的 dir.exists 的属性取决于可用任务的结果真的还是假的。该doFoo目标将只运行如果属性为设置为true,doBar将只运行如果没有设置或设置为false。

The dir.check target is required by both doFoo and doBar, it sets the dir.exists property to true or false depending on the result of the available task. The doFoo target will only run if that propery is set to true and doBar will only run if it is not set or set to false.

<?xml version="1.0"?>
<project name="test" default="doFoo" basedir=".">
  <property name="directory" value="c:\test\directory"/>

  <target name="doFoo" depends="dir.check" if="dir.exists">
    <echo>${directory} exists</echo>
  </target>

  <target name="doBar" depends="dir.check" unless="dir.exists">
    <echo>${directory} missing"</echo>
  </target>

  <target name="dir.check">
    <condition property="dir.exists">
      <available file="${directory}" type="dir"/>
    </condition>
  </target>
</project>

羚羊提供了额外的任务,包括一个如果任务,可以使处理更简单(对我来说,更直观),您可以从下载页面下载羚羊任务。

Antelope provides additional tasks, including an If task that can make the processing simpler (and to me, more intuitive), you can download the Antelope tasks from the download page.

这篇关于难道我有办法来检查蚂蚁目录(不是文件)的存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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