Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In nant, how to delete contents of a directory, but not the directory itself?

Tags:

nant

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?

like image 643
spoulson Avatar asked Sep 22 '10 14:09

spoulson


People also ask

How do I delete files from a directory?

Open My Computer or Windows Explorer. Locate and select the file or folder you want to delete, click File in the top menu bar, and select Delete. If the File menu is not visible in My Computer or Windows Explorer, press the Alt key to make the menu bar visible, including the file menu.

How do I delete a directory and its contents in terminal?

Delete a Directory ( rm -r ) To delete (i.e. remove) a directory and all the sub-directories and files that it contains, navigate to its parent directory, and then use the command rm -r followed by the name of the directory you want to delete (e.g. rm -r directory-name ).


1 Answers

This works for me - no workarounds required:

<delete>
    <fileset basedir="\\server\share">
        <include name="**\*" />
    </fileset>
</delete>
like image 198
robaker Avatar answered Jan 02 '23 15:01

robaker