我们如何在ant中使用特定目录下的文件搜索

时间:2012-05-15 12:43:21

标签: ant

大家好,这是我的代码,用于检查特定文件是否存在,例如${file}=license

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

虽然如果存在的文件是完全许可证,它可以正常工作但有时文件可以是license.txt,甚至也可以是大写。

所以我希望我的上述代码在所有条件下工作,即使该文件是License或LICENSE或许可证或LICENSE.txt或以l或L开头的任何内容。

3 个答案:

答案 0 :(得分:1)

包含所有可能的变体可能最容易,因为file attribute需要一个真实的文件,并且不允许使用通配符:

 <condition property="File.exists" >
    <or>
      <available file="license.txt" type="file" />
      <available file="LICENSE.txt" type="file" />
      <available file="license" type="file" />
      <available file="LICENSE" type="file" />
    </or>
 </condition>

另一种可能性是write your own condition

答案 1 :(得分:1)

您可以使用Contains条件来检查${file}是否包含文本&#34; license&#34;。它甚至有一个casesensitive参数。不确定是否

  

以l或L

开头的任何内容

虽然是一个好主意。

答案 2 :(得分:0)

<target name="SearchForfile">
    <delete dir="../filepresent" />
        <copy todir="../filepresent" failonerror="yes" flatten="true">
            <fileset dir="../result/unzip/${param1}" casesensitive="false"> 
                <include name="**/*license*"/> 
            </fileset>
        </copy>
    <antcall target="CheckFileExistance"/>  
</target>

在那个"CheckFileExistance"目标中只检查"filepresent"文件夹是否存在,如果是,则文件存在于源目录中,否则"filepresent"文件夹不存在文件不存在于您的搜索目录中...我希望这能使一切清晰

相关问题