You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by er...@thomsonreuters.com on 2010/07/29 23:08:40 UTC

Ant: want to copy a file if it exists

I want to check to see if a file exist and if so then copy it.  What is
the best way for performing this conditional task?

 

Thanks, eric


AW: want to copy a file if it exists

Posted by Ja...@rzf.fin-nrw.de.
Just use <copy>.

<copy file tofile/> will fail if the requested file does not exist.
<copy todir><fileset dir includes="the-requested-file/></copy> wont ...


Jan 

>-----Ursprüngliche Nachricht-----
>Von: eric.wood@thomsonreuters.com 
>[mailto:eric.wood@thomsonreuters.com] 
>Gesendet: Donnerstag, 29. Juli 2010 23:09
>An: user@ant.apache.org
>Betreff: Ant: want to copy a file if it exists
>
>I want to check to see if a file exist and if so then copy it.  What is
>the best way for performing this conditional task?
>
> 
>
>Thanks, eric
>
>

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


Re: Ant: want to copy a file if it exists

Posted by Matt Benson <gu...@gmail.com>.
On Jul 30, 2010, at 8:42 AM, Martin Gainty wrote:

>
> A great question!
> i found 2 items that may help:
>
> 1)Javadoc for an Ant Resource:
> http://www.docjar.com/docs/api/org/apache/tools/ant/types/ 
> Resource.html
>

This does communicate the basic idea that a Resource is *like* a File.

> 2)The folks at Simon Fraser put together this user-friendly  
> explanation
> http://www.sfu.ca/cprost/docs/A%20Brief%20Overview%20of%20ANT.pdf

Okay, this link has nothing to do with Apache Ant.  :)

>
> the way I classify a resource is any entity which is not a Java class
> so an (ant) java class can be configured by a resource specifically
> .properties
>
> or a resource which is used to describe schema could be described  
> and defined by a resource specifically:
> xml/xsd
>
> or documents with or without associated view programmes described  
> by a resource specifically:
> pdf/doc
>
> anyone?

Have you read http://ant.apache.org/manual/Types/resources.html ?   
The description of a resourcecollection is on the same page.  So to  
put it simply, if you use a fileset you _are_ using a  
resourcecollection.  About the only thing you could use  
resourcecollections for might be to <restrict> a bunch of atomically- 
specified <file> resources to <exists>; the catch is that <fileset>,  
by virtue of the fact that it discovers files by scanning the  
filesystem and thus _only_ contains files that exist, more or less  
does this for you.  Finally, in the case of the copy task, ask  
yourself:  How would you copy a resource that doesn't exist?  By  
creating a destination file that doesn't exist?  That's crazy  
talk!  :)  So copy simply ignores nonexistent resources.  In this  
particular example your job of only copying a file that exists has  
been done for you first by <fileset> and then by <copy>.  You should  
be covered.  :)

HTH,
Matt

> Martin
> ______________________________________________
> Verzicht und Vertraulichkeitanmerkung/Note de déni et de  
> confidentialité
>
> Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene  
> Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede  
> unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig.  
> Diese Nachricht dient lediglich dem Austausch von Informationen und  
> entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten  
> Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den  
> Inhalt uebernehmen.
> Ce message est confidentiel et peut être privilégié. Si vous n'êtes  
> pas le destinataire prévu, nous te demandons avec bonté que pour  
> satisfaire informez l'expéditeur. N'importe quelle diffusion non  
> autorisée ou la copie de ceci est interdite. Ce message sert à  
> l'information seulement et n'aura pas n'importe quel effet  
> légalement obligatoire. Étant donné que les email peuvent  
> facilement être sujets à la manipulation, nous ne pouvons accepter  
> aucune responsabilité pour le contenu fourni.
>
>
>
>
>
>> Subject: RE: Ant: want to copy a file if it exists
>> Date: Fri, 30 Jul 2010 08:43:30 -0400
>> From: eric.wood@thomsonreuters.com
>> To: user@ant.apache.org
>>
>> I was curious if resource collections were an option to use. To be  
>> honest, I have never fully appreciated resources. Is there a good  
>> tutorial on resources in ANT?
>>
>>
>>
>> -----Original Message-----
>> From: Vimil Saju [mailto:vimilsaju@yahoo.com]
>> Sent: Thursday, July 29, 2010 8:27 PM
>> To: Ant Users List
>> Subject: Re: Ant: want to copy a file if it exists
>>
>> Use the 'available' task to check if a file exists. There is also  
>> an 'if' task which is part of antcontrib that you can use to  
>> execute tasks conditionally
>>
>> --- On Thu, 7/29/10, eric.wood@thomsonreuters.com  
>> <er...@thomsonreuters.com> wrote:
>>
>> From: eric.wood@thomsonreuters.com <er...@thomsonreuters.com>
>> Subject: Ant: want to copy a file if it exists
>> To: user@ant.apache.org
>> Date: Thursday, July 29, 2010, 2:08 PM
>>
>> I want to check to see if a file exist and if so then copy it.   
>> What is
>> the best way for performing this conditional task?
>>
>>
>>
>> Thanks, eric
>>
>>
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>> For additional commands, e-mail: user-help@ant.apache.org
>>
>  		 	   		


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


RE: Ant: want to copy a file if it exists

Posted by Martin Gainty <mg...@hotmail.com>.
A great question!
i found 2 items that may help:

1)Javadoc for an Ant Resource:
http://www.docjar.com/docs/api/org/apache/tools/ant/types/Resource.html

2)The folks at Simon Fraser put together this user-friendly explanation
http://www.sfu.ca/cprost/docs/A%20Brief%20Overview%20of%20ANT.pdf
 
the way I classify a resource is any entity which is not a Java class 
so an (ant) java class can be configured by a resource specifically
.properties

or a resource which is used to describe schema could be described and defined by a resource specifically:
xml/xsd

or documents with or without associated view programmes described by a resource specifically:
pdf/doc
 
anyone?
Martin 
______________________________________________ 
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.



 

> Subject: RE: Ant: want to copy a file if it exists
> Date: Fri, 30 Jul 2010 08:43:30 -0400
> From: eric.wood@thomsonreuters.com
> To: user@ant.apache.org
> 
> I was curious if resource collections were an option to use. To be honest, I have never fully appreciated resources. Is there a good tutorial on resources in ANT?
> 
> 
> 
> -----Original Message-----
> From: Vimil Saju [mailto:vimilsaju@yahoo.com] 
> Sent: Thursday, July 29, 2010 8:27 PM
> To: Ant Users List
> Subject: Re: Ant: want to copy a file if it exists
> 
> Use the 'available' task to check if a file exists. There is also an 'if' task which is part of antcontrib that you can use to execute tasks conditionally
> 
> --- On Thu, 7/29/10, eric.wood@thomsonreuters.com <er...@thomsonreuters.com> wrote:
> 
> From: eric.wood@thomsonreuters.com <er...@thomsonreuters.com>
> Subject: Ant: want to copy a file if it exists
> To: user@ant.apache.org
> Date: Thursday, July 29, 2010, 2:08 PM
> 
> I want to check to see if a file exist and if so then copy it.  What is
> the best way for performing this conditional task?
> 
> 
> 
> Thanks, eric
> 
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 
 		 	   		  

RE: Ant: want to copy a file if it exists

Posted by er...@thomsonreuters.com.
I was curious if resource collections were an option to use.  To be honest, I have never fully appreciated resources.  Is there a good tutorial on resources in ANT?



-----Original Message-----
From: Vimil Saju [mailto:vimilsaju@yahoo.com] 
Sent: Thursday, July 29, 2010 8:27 PM
To: Ant Users List
Subject: Re: Ant: want to copy a file if it exists

Use the 'available' task to check if a file exists. There is also an 'if' task which is part of antcontrib that you can use to execute tasks conditionally

--- On Thu, 7/29/10, eric.wood@thomsonreuters.com <er...@thomsonreuters.com> wrote:

From: eric.wood@thomsonreuters.com <er...@thomsonreuters.com>
Subject: Ant: want to copy a file if it exists
To: user@ant.apache.org
Date: Thursday, July 29, 2010, 2:08 PM

I want to check to see if a file exist and if so then copy it.  What is
the best way for performing this conditional task?

 

Thanks, eric




      

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


Re: Ant: want to copy a file if it exists

Posted by Vimil Saju <vi...@yahoo.com>.
Use the 'available' task to check if a file exists. There is also an 'if' task which is part of antcontrib that you can use to execute tasks conditionally

--- On Thu, 7/29/10, eric.wood@thomsonreuters.com <er...@thomsonreuters.com> wrote:

From: eric.wood@thomsonreuters.com <er...@thomsonreuters.com>
Subject: Ant: want to copy a file if it exists
To: user@ant.apache.org
Date: Thursday, July 29, 2010, 2:08 PM

I want to check to see if a file exist and if so then copy it.  What is
the best way for performing this conditional task?

 

Thanks, eric