在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)