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?
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.
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 ).
This works for me - no workarounds required:
<delete>
<fileset basedir="\\server\share">
<include name="**\*" />
</fileset>
</delete>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With