You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by "Brill, C" <C....@t-systems.com> on 2008/09/09 14:32:29 UTC

How to Check if Directory exists?

Hi,

I've got a little problem.
Here is the existing directory structure:

drwxrwxr-x   5 symosyad   edasql          96 Sep  9 13:14 DWH-PQ-HQ-0837
-rw-r-----   1 symosyad   edasql        3760 Sep  9 13:14
DWH-PQ-HQ-0837_Lieferung.tar.gz
drwxr-xr-x   3 symosyad   edasql          96 Sep  9 13:12 archiv

In one of the first steps in my build.xml I want to check if the file
'DWH-PQ-HQ-0837_Lieferung.tar.gz' and the directory 'DWH-PQ-HQ-0837'
exist.
If the exist I want to move them into 'archiv'.
With the <available> task I can only check if files exists, isn't it?
Here is the target from my build.xml:

<target name="archiv" description="move last delivery into archiv ...">
	<!-- copy recent packages to archiv -->
	<copy todir="${name.dir.archiv}">
 		<fileset dir="${name.dir.projekt}">
    			<include name="**"/>
    			<exclude name="archiv"/>
    		</fileset>
    	</copy>
    	<!-- clean directory ${name.dir.projekt} -->
    	<dirset id="deldir" dir="${name.dir.projekt}">
    		<include name="*"/>
    		<exclude name="archiv"/>
    	</dirset>
    	<delete>
		<fileset dir="${name.dir.projekt}">
			<include name="*.gz"/>
		</fileset> 
	</delete>
    	<for delimiter=";" list="${toString:deldir}" param="name.dir">
    		<sequential>
				<delete
dir="${name.dir.projekt}/@{name.dir}"/>
			</sequential>
	</for>
</target>

Thanks for your help!

Christoph


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


RE: How to Check if Directory exists?

Posted by "Rebhan, Gilbert" <Gi...@huk-coburg.de>.
-----Original Message-----
From: Brill, C [mailto:C.Brill@t-systems.com]
Sent: Tuesday, September 09, 2008 2:32 PM
To: user@ant.apache.org
Subject: How to Check if Directory exists?

/*
Hi,

I've got a little problem.
Here is the existing directory structure:

drwxrwxr-x   5 symosyad   edasql          96 Sep  9 13:14 DWH-PQ-HQ-0837
-rw-r-----   1 symosyad   edasql        3760 Sep  9 13:14
DWH-PQ-HQ-0837_Lieferung.tar.gz
drwxr-xr-x   3 symosyad   edasql          96 Sep  9 13:12 archiv

In one of the first steps in my build.xml I want to check if the file
'DWH-PQ-HQ-0837_Lieferung.tar.gz' and the directory 'DWH-PQ-HQ-0837'
exist.
If the exist I want to move them into 'archiv'.
With the <available> task I can only check if files exists, isn't it?
*/

<condition property="tobemoved">
 <and>
  <available file="/path/to/DWH-PQ-HQ-0837_Lieferung.tar.gz"/>
  <available file="/path/to/DWH-PQ-HQ-0837/>"
 </and>
</condition>
...

<target name="archive" if="tobemoved">
...
</target>

Regards, Gilbert

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


Re: How to Check if Directory exists?

Posted by "Scot P. Floess" <fl...@mindspring.com>.
You can use a directory name for the file attribute - if it exists, it 
will be set (it being the directory).

On Tue, 9 Sep 2008, Brill, C wrote:

> Hi,
>
> I've got a little problem.
> Here is the existing directory structure:
>
> drwxrwxr-x   5 symosyad   edasql          96 Sep  9 13:14 DWH-PQ-HQ-0837
> -rw-r-----   1 symosyad   edasql        3760 Sep  9 13:14
> DWH-PQ-HQ-0837_Lieferung.tar.gz
> drwxr-xr-x   3 symosyad   edasql          96 Sep  9 13:12 archiv
>
> In one of the first steps in my build.xml I want to check if the file
> 'DWH-PQ-HQ-0837_Lieferung.tar.gz' and the directory 'DWH-PQ-HQ-0837'
> exist.
> If the exist I want to move them into 'archiv'.
> With the <available> task I can only check if files exists, isn't it?
> Here is the target from my build.xml:
>
> <target name="archiv" description="move last delivery into archiv ...">
> 	<!-- copy recent packages to archiv -->
> 	<copy todir="${name.dir.archiv}">
> 		<fileset dir="${name.dir.projekt}">
>    			<include name="**"/>
>    			<exclude name="archiv"/>
>    		</fileset>
>    	</copy>
>    	<!-- clean directory ${name.dir.projekt} -->
>    	<dirset id="deldir" dir="${name.dir.projekt}">
>    		<include name="*"/>
>    		<exclude name="archiv"/>
>    	</dirset>
>    	<delete>
> 		<fileset dir="${name.dir.projekt}">
> 			<include name="*.gz"/>
> 		</fileset>
> 	</delete>
>    	<for delimiter=";" list="${toString:deldir}" param="name.dir">
>    		<sequential>
> 				<delete
> dir="${name.dir.projekt}/@{name.dir}"/>
> 			</sequential>
> 	</for>
> </target>
>
> Thanks for your help!
>
> Christoph
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>

Scot P. Floess
27 Lake Royale
Louisburg, NC  27549

252-478-8087 (Home)
919-754-4592 (Work)

Chief Architect JPlate   http://sourceforge.net/projects/jplate
Chief Architect JavaPIM  http://sourceforge.net/projects/javapim

Architect Keros          http://sourceforge.net/projects/keros

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


RE: How to Check if Directory exists?

Posted by "Peters, John" <Jo...@bcbsfl.com>.
No available checks directories too.

http://ant.apache.org/manual/CoreTasks/available.html
Sets a property if a resource is available at runtime. 
This resource can be a file, a directory, a class in the classpath, or a
JVM system resource. 

-----Original Message-----
From: Brill, C [mailto:C.Brill@t-systems.com] 
Sent: Tuesday, September 09, 2008 8:32 AM
To: user@ant.apache.org
Subject: How to Check if Directory exists?

Hi,

I've got a little problem.
Here is the existing directory structure:

drwxrwxr-x   5 symosyad   edasql          96 Sep  9 13:14 DWH-PQ-HQ-0837
-rw-r-----   1 symosyad   edasql        3760 Sep  9 13:14
DWH-PQ-HQ-0837_Lieferung.tar.gz
drwxr-xr-x   3 symosyad   edasql          96 Sep  9 13:12 archiv

In one of the first steps in my build.xml I want to check if the file
'DWH-PQ-HQ-0837_Lieferung.tar.gz' and the directory 'DWH-PQ-HQ-0837'
exist.
If the exist I want to move them into 'archiv'.
With the <available> task I can only check if files exists, isn't it?
Here is the target from my build.xml:

<target name="archiv" description="move last delivery into archiv ...">
	<!-- copy recent packages to archiv -->
	<copy todir="${name.dir.archiv}">
 		<fileset dir="${name.dir.projekt}">
    			<include name="**"/>
    			<exclude name="archiv"/>
    		</fileset>
    	</copy>
    	<!-- clean directory ${name.dir.projekt} -->
    	<dirset id="deldir" dir="${name.dir.projekt}">
    		<include name="*"/>
    		<exclude name="archiv"/>
    	</dirset>
    	<delete>
		<fileset dir="${name.dir.projekt}">
			<include name="*.gz"/>
		</fileset> 
	</delete>
    	<for delimiter=";" list="${toString:deldir}" param="name.dir">
    		<sequential>
				<delete
dir="${name.dir.projekt}/@{name.dir}"/>
			</sequential>
	</for>
</target>

Thanks for your help!

Christoph


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






Blue Cross Blue Shield of Florida, Inc., and its subsidiary and affiliate companies are not responsible for errors or omissions in this e-mail message. Any personal comments made in this e-mail do not reflect the views of Blue Cross Blue Shield of Florida, Inc.  The information contained in this document may be confidential and intended solely for the use of the individual or entity to whom it is addressed.  This document may contain material that is privileged or protected from disclosure under applicable law.  If you are not the intended recipient or the individual responsible for delivering to the intended recipient, please (1) be advised that any use, dissemination, forwarding, or copying of this document IS STRICTLY PROHIBITED; and (2) notify sender immediately by telephone and destroy the document. THANK YOU.


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