Cannot delete a file even when logged in as an Administrator [closed]
Asked Answered
H

1

54

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.

Hermilahermina answered 11/9, 2014 at 23:1 Comment(9)
Check who does have permissions. Take control as appropriate. (I'm a windows schmuck, so I only know to do that from the UI.)Microtone
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.Hermilahermina
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?Budget
superuser.com/a/423821/96662Misspend
possible duplicate of Permission errors in PowerShellAllude
Are you sure this is not a duplicate of Permission errors in PowerShell?Allude
Thank you Matt the -recurse and -force helps!Hermilahermina
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.Pulpboard
This question is discussed on metaAngkor
B
132

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

Budget answered 12/9, 2014 at 11:10 Comment(6)
Matt, so if using -Recurse - Force, does work for the developer, than this is not a UAC issue? Is that correct?Industrialist
The cmdlet is still affected by Uac if enabled. Just using those switches won't change thatBudget
For me the file was read-only, so using -Force eliminated the problemProsciutto
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.Collocate
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`Trinia
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 :/Nakashima

© 2022 - 2024 — McMap. All rights reserved.