tags:

views:

57

answers:

3

Suppose I were scripting a deployment using nant on a Windows server to a file share: \\server\share. I want a nant script to delete all files from the share then copy in new files.

I have this code to delete the files, but I'm getting an error that it can't delete "\server\share". But I didn't want to delete the share, just the contents in it.

<delete>
   <fileset basedir="\\server\share">
      <include name="**/**" />
   </fileset>
</delete>

Output:

BUILD FAILED

D:\code\xxx\xxx.deploy(177,8):
Cannot delete directory '\\server\share'.
    Access to the path '\\server\share' is denied.

If I modified it to instead delete contents of a directory in the share, say \\server\share\somedir, it'll delete "somedir" without error. But still, I didn't want to delete the dir, just the contents. Is there a way?

+1  A: 

You could introduce an "exclude" tag and exclude a dummy file. That'll leave the root folder intact.

I'm using the following:

  <target name="clean">
    <delete>
      <fileset basedir="${DeployTo}">
        <include name="**/*" />
        <exclude name="**/aspnet_client/**" />
      </fileset>
    </delete>
  </target>
nsr81
A: 

Taking cue from nsr81, I was able to come up with this workaround that works for me:

<touch file="${DeployTo}/deleteme" />
<delete>
   <fileset basedir="${DeployTo}">
      <include name="**/**" />
      <exclude name="deleteme" />
   </fileset>
</delete>
<delete file="${DeployTo}/deleteme" />
spoulson
+1  A: 

This works for me - no workarounds required:

<delete>
    <fileset basedir="\\server\share">
        <include name="**\*" />
    </fileset>
</delete>
robaker
Tried this and it worked! Funny, I never saw this syntax in the nant docs.
spoulson