You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by nissea <ni...@ngai.se> on 2007/10/09 18:15:13 UTC

Check if a directory is empty

Hi

I would like to check if a directory is empty and not include any files, and
if it is empty I would like to do something and if it's not I would like to
do another thing, quite like an If-statement? Does anyone know how to do
this?

regards
Nils
-- 
View this message in context: http://www.nabble.com/Check-if-a-directory-is-empty-tf4595246.html#a13118887
Sent from the Ant - Users mailing list archive at Nabble.com.


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


Re: Check if a directory is empty

Posted by nissea <ni...@ngai.se>.
OK, Thank you so much!




David Weintraub wrote:
> 
> Hmmm...
> 
> You could create a PATH ID, then convert that over to a property, then
> check that the property is not empty. The following build.xml has been
> tested and checks for the presents of files in that directory.
> However, it will report a directory as empty if it contains just empty
> directories:
> 
> <project name="test" default="test" basedir=".">
> 
>     <path id="test.me">
>         <fileset dir="${basedir}/test.dir"/>
>     </path>
> 
>     <property name="test.me.property" refid="test.me"/>
> 
>     <condition property="empty.dir.flag">
>         <equals arg1="" arg2="${test.me.property}"/>
>     </condition>
> 
>     <target name="test1"
>         if="empty.dir.flag">
>         <echo>Directory "test.dir" is empty</echo>
>     </target>
> 
>     <target name="test"
>         depends="test1"
>         unless="empty.dir.flag">
>         <echo>Directory "test.dir" is not empty</echo>
>     </target>
> </project>
> 
> I was seeing if there was someway to do this via a filterchange, but
> couldn't see anyway.
> 
> --
> David Weintraub
> qazwart@gmail.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Check-if-a-directory-is-empty-tf4595246.html#a13130373
Sent from the Ant - Users mailing list archive at Nabble.com.


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


Re: Check if a directory is empty

Posted by David Weintraub <qa...@gmail.com>.
Hmmm...

You could create a PATH ID, then convert that over to a property, then
check that the property is not empty. The following build.xml has been
tested and checks for the presents of files in that directory.
However, it will report a directory as empty if it contains just empty
directories:

<project name="test" default="test" basedir=".">

    <path id="test.me">
        <fileset dir="${basedir}/test.dir"/>
    </path>

    <property name="test.me.property" refid="test.me"/>

    <condition property="empty.dir.flag">
        <equals arg1="" arg2="${test.me.property}"/>
    </condition>

    <target name="test1"
        if="empty.dir.flag">
        <echo>Directory "test.dir" is empty</echo>
    </target>

    <target name="test"
        depends="test1"
        unless="empty.dir.flag">
        <echo>Directory "test.dir" is not empty</echo>
    </target>
</project>

I was seeing if there was someway to do this via a filterchange, but
couldn't see anyway.

--
David Weintraub
qazwart@gmail.com

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