user1387014
user1387014

Reputation: 1

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 e.g. ${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.

Upvotes: 0

Views: 113

Answers (3)

user1387014
user1387014

Reputation: 1

<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

Upvotes: 0

DoctorRuss
DoctorRuss

Reputation: 1439

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.

Upvotes: 1

oers
oers

Reputation: 18704

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.

Upvotes: 1

Related Questions