-----Original Message-----
From: cvsusr [mailto:[email protected]]
Sent: Thursday, October 29, 2009 12:00 PM
To: [email protected]
Subject: Alternative for <available> taks to check a pattern of file existence
/*
Hi,
I need to check for existence of files with some extension say *.txt in a
folder and if present execute a target..
I found only <available> task which checks for the existence of single file
only when the name of the file known. I wanted to check whether *.txt is
present or not.. if present execute a target..
*/
one possible solution, the extension you're are looking for is
part of the glob attribute =
your/path/**/*.yourextension means recursive
your/path/*.yourextension means non recursive
examplescript, look for files with .xml extension in C:/Temp
and set property with number of found files
the condition checks whether there are *.xml files in C:/Temp
- means property set by scriptdef != 0
and then your targets use if / unless with condition property
<project name="bla" default="main" basedir=".">
<scriptdef name="filecount" language="ruby">
<attribute name="glob"/>
<attribute name="property"/>
$project.setProperty "#{$attributes.get('property')}",
Dir.glob("#{$attributes.get('glob')}").length.to_s
</scriptdef>
<target name="checkfiles">
<filecount glob="C:/Temp/**/*.xml" property="xmlfiles"/>
<condition property="files">
<not>
<equals arg1="${xmlfiles}" arg2="0" />
</not>
</condition>
</target>
<target name="foo" if="files">
<echo>${xmlfiles} files found ..</echo>
</target>
<target name="foobar" unless="files">
<echo>no files found ..</echo>
</target>
<target name="main" depends="checkfiles,foo,foobar"/>
</project>
Regards, Gilbert
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]