You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Rohit P <ro...@gmail.com> on 2008/11/18 10:16:28 UTC

Verifying existence of files under a directory

Hi,

As part of my build script i need to 'concat' set of files [with similar
extension] under a directory into a .csv file.

...
...
       <property name="REPORTS_DIR" value="C:\Reports\LogDir"/>
...
        <concat destfile="C:\abc.csv" force="no">
            <fileset dir="${REPORTS_DIR}"
                includes="*.csv"/>
        </concat>
...
...
...

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

Thanks
Rohit

RE: Verifying existence of files under a directory

Posted by "Rebhan, Gilbert" <Gi...@huk-coburg.de>.

-----Original Message-----
From: Rohit P [mailto:rohitmp.for@gmail.com]
Sent: Tuesday, November 18, 2008 11:39 AM
To: Ant Users List
Subject: Re: Verifying existence of files under a directory
/*
Thanks Gilbert for quick response.
The first solution would be suitable for my current issue &  it worked out.
*/

Solution 3. is very similar

/*
Currently i am using Ant1.6.5 and in Ant Manual [for 1.6.5] for FileSets i
don't see "id" attribute in the Attribute || Description || Required table.
Can you please check if this information is updated in ant1.7 manual?
*/

the same for ant 1.7.1, see =
http://ant.apache.org/manual/CoreTypes/fileset.html


Regards, Gilbert

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Verifying existence of files under a directory

Posted by Rohit P <ro...@gmail.com>.
Thanks Gilbert for quick response.
The first solution would be suitable for my current issue &  it worked out.

Currently i am using Ant1.6.5 and in Ant Manual [for 1.6.5] for FileSets i
don't see "id" attribute in the Attribute || Description || Required table.
Can you please check if this information is updated in ant1.7 manual?

Thanks once again

Regards
Rohit

On Tue, Nov 18, 2008 at 3:34 PM, Rebhan, Gilbert <
Gilbert.Rebhan@huk-coburg.de> wrote:

> -----Original Message-----
> From: Rohit P [mailto:rohitmp.for@gmail.com]
> 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="" />
> </condition>
>
> <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"/>
> <![CDATA[
>  $project.setNewProperty $attributes.get('property'),
>
>  Dir.glob("#{$attributes.get('dir')}/**/*.#{$attributes.get('ext')}").length.to_s
>  puts "Result = " +
> Dir.glob("#{$attributes.get('dir')}/**/*.#{$attributes.get('ext')}").length.to_s
> ]]>
> </scriptdef>
>
> <filecount dir="${REPORTS.DIR}" ext="csv" property="filecount"/>
> <condition property="nofiles">
>  <equals arg1="${filecount}" arg2="0" />
> </condition>
> <fail if="nofiles" message="No Files around !!" />
>
>
> Regards, Gilbert
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>

RE: Verifying existence of files under a directory

Posted by "Rebhan, Gilbert" <Gi...@huk-coburg.de>.

-----Original Message-----
From: Rebhan, Gilbert [mailto:Gilbert.Rebhan@huk-coburg.de]
Sent: Tuesday, November 18, 2008 11:05 AM
To: 'Ant Users List'
Subject: RE: Verifying existence of files under a directory

-----Original Message-----
From: Rohit P [mailto:rohitmp.for@gmail.com]
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 =

...

another one =

3.
<pathconvert property="filesfound" setonempty="false">
    <fileset dir="${REPORTS.DIR}" includes="**/*.bla"/>
  </pathconvert>

and put your concat action in a target

<target name="concat" if=filesfound">
...
</target>


Regards, Gilbert

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: Verifying existence of files under a directory

Posted by "Rebhan, Gilbert" <Gi...@huk-coburg.de>.
-----Original Message-----
From: Rohit P [mailto:rohitmp.for@gmail.com]
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="" />
</condition>

<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"/>
<![CDATA[
  $project.setNewProperty $attributes.get('property'),
    Dir.glob("#{$attributes.get('dir')}/**/*.#{$attributes.get('ext')}").length.to_s
  puts "Result = " + Dir.glob("#{$attributes.get('dir')}/**/*.#{$attributes.get('ext')}").length.to_s
]]>
</scriptdef>

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


Regards, Gilbert


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org