蚂蚁检查存在于一组文件 [英] Ant check existence for a set of files
问题描述
在蚂蚁,我怎么能检查是否存在或不是一组文件(路径逗号分隔的列表)的?
In ant, how can i check if a set of files (comma-separated list of paths) exist or not?
例如我需要检查是否存在 myprop
中列出的所有路径,如果是的话我想设置一个属性 pathExist
:
For example I need to check if all paths listed in myprop
exist and if so i want to set a property pathExist
:
<property name="myprop" value="path1,path2,path3"/>
因此在本例中所有的路径1
路径2
path3时
必须存在设置 pathExist
到真正
,否则假
So in the example all of path1
path2
path3
must exist to set pathExist
to true
, otherwise false
.
我发现了一个单一的资源,我可以使用 resourceexist
的任务,但我无法弄清楚如何使用用逗号分隔的路径列表。
I discovered that for a single resource I can use the resourceexist
task, but i can't figure out how to use that with a comma-separated list of paths.
我如何检查是否存在一组路径?谢谢!
How can I check the existence for a set of paths? Thanks!
推荐答案
You can use a combination of a filelist
, restrict
and condition
task for this.
在下面的示例文件列表是从文件的逗号分隔的列表中的属性创建。使用限制
不存在的文件的列表中找到。这被放置在如果所有的文件中找到,这将是一空的属性
In the below example a filelist is created from the property with the comma-separated list of files. Using restrict
a list of the files that don't exist is found. This is placed in a property which will be empty if all the files are found.
<property name="myprop" value="path1,path2,path3"/>
<filelist id="my.files" dir="." files="${myprop}" />
<restrict id="missing.files">
<filelist refid="my.files"/>
<not>
<exists/>
</not>
</restrict>
<property name="missing.files" refid="missing.files" />
<condition property="pathExist" value="true" else="false">
<length string="${missing.files}" length="0" />
</condition>
<echo message="Files all found: ${pathExist}" />
您可以使用像这样生成一个失败消息,列出丢失的文件:
You could use something like this to generate a failure message listing the missing files:
<fail message="Missing files: ${missing.files}">
<condition>
<length string="${missing.files}" when="greater" length="0" />
</condition>
</fail>
这篇关于蚂蚁检查存在于一组文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!