You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Cyriaque Dupoirieux <cy...@pcotech.fr> on 2001/07/03 14:57:56 UTC

condition in a copy

Hello,

   I want to copy a file, but this file may not exist.
   <copy file="my.properties" todir="codes"/>
   And if the file doesn't exist, I have the following message :
       [copy] Could not find file my.properties to copy.

   I have the same problem with a directory :
       <copy todir="codes/images" >
           <fileset dir="sources/images"/>
       </copy>
   The error message is :
       D:\build.xml:133: sources\images not found.

   How can I test the existance of files or directories ? (available 
target ?)


Thanks & Regards,

-- 
Cyriaque Dupoirieux
PCO Technologies
Burolines - 2 ter rue Marcel Doret
31700 Blagnac
Tél : 05 34 60 44 13 - Fax : 05 34 60 44 10


Re: condition in a copy

Posted by Martin Gerlach <ge...@planb-media.de>.

Cyriaque Dupoirieux wrote:
> 
> Hello,
> 
>    I want to copy a file, but this file may not exist.
>    <copy file="my.properties" todir="codes"/>
>    And if the file doesn't exist, I have the following message :
>        [copy] Could not find file my.properties to copy.
> 
>    I have the same problem with a directory :
>        <copy todir="codes/images" >
>            <fileset dir="sources/images"/>
>        </copy>
>    The error message is :
>        D:\build.xml:133: sources\images not found.
> 
>    How can I test the existance of files or directories ? (available
> target ?)
> 
> Thanks & Regards,
> 

<target name="isAvailable">
  <available file="yourFile.txt"
    property="yourFile.txt.available"/>
</target>

<target name="copy" depends="isAvailable"
  if="yourFile.txt.available">
  <copy file="yourFile.txt" tofile="yourFile.txt.backup"/>
</target>

Insert these two targets to your build.xml. 
call 
> ant copy
it will only do a backup if the property yourFile.txt.available
is set. the Property yourFile.txt.available will be set via 
target isAvailable (if the file yourFile.txt is present)

Hope that helps. Works fine foe me 

-- 
_______________________________________________________________

    Martin Gerlach                Distributed Systems
    
    phone: +49 (0)221 250-1046    mailto:gerlach@imigo.de
    fax:   +49 (0)221 250-1588    http://www.planb-media.de
    
    plan_b media ag               Coloneum
    Butzweilerstr. 255            D-50829 Cologne, Germany
_______________________________________________________________

Re: condition in a copy

Posted by Cyriaque Dupoirieux <cy...@pcotech.fr>.
Hello again,

   Alright, I have found a solution to my previous problem using the 
available target...

   But, I need know to make a copy of files but to keep a backup 
(fic.bak) of each file updated.

   How can I do this ?

Cyriaque Dupoirieux wrote:

> Hello,
> 
>   I want to copy a file, but this file may not exist.
>   <copy file="my.properties" todir="codes"/>
>   And if the file doesn't exist, I have the following message :
>       [copy] Could not find file my.properties to copy.
> 
>   I have the same problem with a directory :
>       <copy todir="codes/images" >
>           <fileset dir="sources/images"/>
>       </copy>
>   The error message is :
>       D:\build.xml:133: sources\images not found.
> 
>   How can I test the existance of files or directories ? (available 
> target ?)
> 
> 
> Thanks & Regards,
> 

-- 
Cyriaque Dupoirieux
PCO Technologies
Burolines - 2 ter rue Marcel Doret
31700 Blagnac
Tél : 05 34 60 44 13 - Fax : 05 34 60 44 10