在ant中,我如何检查是否存在一组文件(以逗号分隔的路径列表)?
例如,我需要检查列出的所有路径是否myprop
存在,如果是,我想设置属性pathExist
:
<property name="myprop" value="path1,path2,path3"/>
Run Code Online (Sandbox Code Playgroud)
因此,在示例中,所有path1
path2
path3
必须存在以设置pathExist
为true
,否则false
.
我发现对于单个资源我可以使用该resourceexist
任务,但我无法弄清楚如何使用逗号分隔的路径列表.
如何检查一组路径的存在?谢谢!
mar*_*ton 12
您可以使用的一个组合filelist
,restrict
并且condition
该任务.
在下面的示例中,将使用逗号分隔的文件列表从属性创建文件列表.找到使用restrict
不存在的文件列表.这被放置在一个属性中,如果找到所有文件,该属性将为空.
<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}" />
Run Code Online (Sandbox Code Playgroud)
您可以使用类似的方法生成列出丢失文件的失败消息:
<fail message="Missing files: ${missing.files}">
<condition>
<length string="${missing.files}" when="greater" length="0" />
</condition>
</fail>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
12118 次 |
最近记录: |