NAnt – Checking to see if a file already exists.

Again, trying to find out how to do this today there seemed a lack of examples out there.

I’ve got a web app which will fail if certain config files aren’t present.   I don’t want to automatically overwrite the existing files in the UAT or Production environments as they contain information relevant to that environment but the site will fail if they’re not there.     The following simply checks to see if the file already exists in the target environment and if it doesn’t it’ll copy them across. 

<if test="${not file::exists('${target.dir}\config\siteinfo.xml')}">
  <echo> Site info  is missing!!!!! </echo>  
  <copy todir="${target.dir}/config">
    <fileset basedir="${source.dir}/config">
      <include name="siteinfo.xml"/>
    </fileset>
  </copy>  
</if>  
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s