ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rebhan, Gilbert" <>
Subject RE: Verifying existence of files under a directory
Date Tue, 18 Nov 2008 10:04:46 GMT
-----Original Message-----
From: Rohit P []
Sent: Tuesday, November 18, 2008 10:16 AM
To: Ant Users List
Subject: Verifying existence of files under a directory

But before i do the 'concat' action i need to verify if there are files
under ${REPORTS_DIR}. Can you let me know the ways to check if *.csv files
exist under ${REPORTS_DIR} before concatenating them into 'abc.csv'?

two possible solutions =

1. use your fileset, just checking if your fileset catches
    any files

<fileset dir="${REPORTS.DIR}" includes="**/*.csv" id="checkdir"/>

<condition property="nofiles">
 <equals arg1="${toString:checkdir}" arg2="" />

<fail if="nofiles" message="No Files around !!" />

2. or use script, with a scripting language you like
     if you need to check for a certain quantity of files

<scriptdef name="filecount" language="ruby">
<attribute name="dir"/>
<attribute name="ext"/>
<attribute name="property"/>
  $project.setNewProperty $attributes.get('property'),
  puts "Result = " + Dir.glob("#{$attributes.get('dir')}/**/*.#{$attributes.get('ext')}").length.to_s

<filecount dir="${REPORTS.DIR}" ext="csv" property="filecount"/>
<condition property="nofiles">
  <equals arg1="${filecount}" arg2="0" />
<fail if="nofiles" message="No Files around !!" />

Regards, Gilbert

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message