简体   繁体   中英

How can we use search for a file under particular directory in ant

Hi all this is my code for checking if a particular file is present eg ${file}=license

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

although if the file present is exactly license it works fine but sometimes the file can be either license.txt or even in uppercase also.

So I want my above code to work under all conditions even if the file is License or LICENSE or license or LICENSE.txt or anything that starts with l or L.

It probably would be easiest to include all possible variations, as the file attribute needs a real file and does not allow wildcards:

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

The other possibility is to write your own condition .

You could use the Contains condition to check whether ${file} contains the text "license". It even has a casesensitive argument. Not sure whether

anything that starts with l or L

is a good idea though.

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

in that "CheckFileExistance" target just check if "filepresent" folder is present or not if it is then the file is present in your source directory and else if "filepresent" folder is not there that means file is not present anywhere in your search directory...i hope this makes everything clear

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM