When trying to delete a file from a network location via windows (I am on windows 7) batch file using a "del" command with /f and /q flags, I see an "Access is denied." message, and the file is not deleted. However, I can successfully delete the file manually through the windows explorer.
I have been running the batch file with my personal user account, which should use the same permissions as manually deleting through windows explorer.
There is nothing special about the file I am trying to delete, it is a blank text file that I created for testing after I noticed that some of our automation code couldn't delete files from this location.
This issue is only present on one specific network share, in all other locations, I can delete files with windows batch files with no issue.
Additionally, I can successfully create a text file in the network location in question without any problems via a batch file. It is just the delete command that gives me the "Access is denied." issue.
My account is in a group that does not have access to the Share holding the folder in question, but does have access to the folder on the share. The way the security is setup for this network location is as follows:
\\Server\Share\Folder1
\\Server\Share\Folder2Where the group my account is in has "modify" access to Folder1 and Folder2, but not Share.
Edit:The command line in question, as requested:
del \\Server\Share\Folder\TEST_FILE.txt /F /QDoes anyone know any network/security phenomenon that could be causing this issue, and how can I fix it?
22 Answers
I'm not sure why this is happening, but I suspect the del command does not support UNC path names properly.
I could easily reproduce this, and the error went away when I used a mapped drive:
del \\share\folder\file.txt
:: got an error 'Access denied'
net use Z: \\share\folder
del Z:\file.txt
:: file deleted successfullyStrangely enough, other commands did work. For instance, I could create a subdirectory, move the file there and then delete the subdirectory:
mkdir \\share\folder\trash
move \\share\folder\file.txt \\share\folder\trash
rmdir /s /q \\share\folder\trash 1 The command 'del \y\x' does a search in 'y' for all files matching 'x', so you'll need list-directory access on 'y'.
With regard to network shares, the access you get is the intersection of permissions on the share and on the object you're accessing, If a file permits you write, but the share does not, then you can't write.
1