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:


Where 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 /Q

Does anyone know any network/security phenomenon that could be causing this issue, and how can I fix it?

  • Can you share all of, or at least the important part, of your BAT file? Dec 1, 2018 at 1:23
  • Yes, updated the post with that info @YetAnotherRandomUser
    – roger21
    Dec 3, 2018 at 17:55

2 Answers 2


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 successfully

Strangely 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
  • Wow, this actually worked for me. Very strange that i'm only experiencing this issue on one network share, but hey, if it works, it works. Thanks!
    – roger21
    Nov 30, 2018 at 15:55

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
    Thanks for the answer, want to clarify some things. When you say ill need “list-directory access on y”, if i can see \x directory contents in windows explorer, does that mean i have that access? Second, if i can create the file manually and write to it manually, does that not mean i have access to the object im accessing?
    – roger21
    Nov 30, 2018 at 4:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.