52

Please could some tell me what I am doing wrong. I am trying to delete hidden folder through command line. I am running the command line as administrator but still getting message insufficient access.

Here is screenshot of my command line :

enter image description here

Here is the code i am trying

rmdir "c:\xampp\htdocs\prestashop\dfs"

I am getting errors like:

Cannot remove item .... You do not have sufficient access rights to perform this operation.
mpromonet
  • 11,326
  • 43
  • 62
  • 91
user2061853
  • 627
  • 1
  • 7
  • 11
  • 1
    Check who does have permissions. Take control as appropriate. (I'm a windows schmuck, so I only know to do that from the UI.) – user2864740 Sep 11 '14 at 23:02
  • Thank for tip but I am logged in as administrator with full control. I guess it must be something with command line because I can delete the file through the UI but not in command line. – user2061853 Sep 11 '14 at 23:20
  • 3
    Just because you are an admin doesn't automatically mean you have rights. Have you checked the permissions of the files in question just to be sure. Are the files in use perhaps? Although if that was the case i would expect `access is denied` Have you tried also using `-recurse` and `-force` to be sure it gets them all? – Matt Sep 11 '14 at 23:25
  • http://superuser.com/a/423821/96662 – Harry Johnston Sep 11 '14 at 23:37
  • 1
    possible duplicate of [Permission errors in PowerShell](http://stackoverflow.com/questions/7738571/permission-errors-in-powershell) – JPBlanc Sep 12 '14 at 03:23
  • Are you sure this is not a duplicate of [Permission errors in PowerShell](http://stackoverflow.com/q/7738571/608772)? – JPBlanc Sep 12 '14 at 03:24
  • 2
    Thank you Matt the -recurse and -force helps! – user2061853 Sep 12 '14 at 07:19
  • Had a similar problem, but wanted to remove a file which used to had Subversion repository checked out with Tortoise SVN. Had to kill Tortoise SVN Cache process from Task Manager and could remove the file with no problems. The "UnauthorizedAccessException" message was a bit misleading in this case. – AndrewMcCoist Dec 19 '16 at 15:40
  • 1
    This question is [discussed on meta](https://meta.stackoverflow.com/q/418644) – Bill Tür stands with Ukraine Jun 11 '22 at 11:13

1 Answers1

122

Just because you are an admin doesn't automatically mean you have rights. Are you running PowerShell as an elevated user (UAC)? Have you checked the permissions of the files in question just to be sure? Are the files in use perhaps? Although if that was the case I would expect access is denied.

Have you tried also using -recurse and -force to be sure it gets them all? For what its worth rmdir is an alias for Remove-Item

Remove-Item "c:\xampp\htdocs\prestashop\dfs" -Recurse -Force

You will see, from TechNet, that -Force

Allows the cmdlet to remove items that cannot otherwise be changed, such as hidden or read-only files

Matt
  • 45,022
  • 8
  • 78
  • 119
  • Matt, so if using -Recurse - Force, does work for the developer, than this is not a UAC issue? Is that correct? – klewis Apr 29 '17 at 16:42
  • The cmdlet is still affected by Uac if enabled. Just using those switches won't change that – Matt Apr 29 '17 at 17:07
  • 14
    For me the file was read-only, so using -Force eliminated the problem – Matt Ruwe Jun 02 '17 at 18:51
  • 2
    Just to add, I once needed to run an elevated PowerShell, to run `bash.exe` within it, and from within the elevated bash I needed to `sudo rm -rf folder` to finally successfully delete it. Pretty elevated stuff. – Bruno Finger Apr 20 '18 at 08:25
  • How do we change the permissions? I have run this below command. It still didn't work. ` icacls.exe "c:\path\to\file" /grant:r "adminuser:(F)" /C` – Kiran Nov 20 '20 at 14:34
  • Nothing above works - still access denied. My problem was with Docker images on Windows - I wanted to remove them as files. I needed to take ownership of all files then add permissions for myself. However, it had still only worked via explorer :/ – Mr Patience Jun 20 '22 at 09:12