If you do a reinstall of Windows 7 or Vista sometimes you may get files and folders that you cannot delete. I have also had directories on an external drive that I can’t delete when installing an application from that drive.
You will get an error message that access is denied.
This is usually because the file is locked with access control for an account that no longer exists.
To take control of the folder containing the undeletable create a text file called “delete.bat” and add the following lines to it:
SET DIRECTORY_NAME="C:\Locked Directory"
TAKEOWN /f %DIRECTORY_NAME% /r /d y
ICACLS %DIRECTORY_NAME% /grant administrators:F /t
PAUSE
You will need to change the directory path to match your requirements e.g. “C:\Locked Directory” to “C:\Delete Me”.
Right click on the file “delete.bat” select “Run As Administrator” and you should now have full control of the directory and all sub directories meaning you can do what you wish with them.
Thanks for the help, just gotta hate windows…
Brilliant! Thank you.
awesome .. helped me
thanx dude ..
Excellent.
Yeesssss, thx so much. Ive been looking for a few hours now how to delete that damn folder. Thanks again, u r a LEGEND.
it doesnt solve my problem when i try to paste the delete.bat file in it , it gives the same error again
Yeeessss, finally!!!! 10x dude, works perfectly
These few sentences saved my life!
Thanks dude
Why can’t microsoft fix this (using win7 64 bit – as administrator), it seems they have taken the permission factor overboard to the detrement of the OS. Your little fix really worked and you have my gratitude!!
Cheers
omg! Can we try English for ppl that don’t get the computer very well!
Hi try right clicking on your desktop select new text document. copy the text that starts with SET DIRECTORY_NAME and ends in PAUSE and paste it into the new text document. Alter the name of the directory to that which you are trying to take ownership of. Save the text document (select save as type all files) with the name ‘delete.bat’ minus the quotation marks. Right click on the delete.bat file and select run as administrator.
THANK YOU AND THANKS SUPERUSERS to link me to this
Tried this but I cannot run the file as administrator? I save it as all files but when I right click the icon, there is no ‘run as administrator’
Have a virus, will not remove the virus files. Got security shield virus a week ago and restored my computer but the files were left behind and it still runs the virus though it only runs in the background. I tried your solution but it still denied me permission to delete the files.
worked like a charm..thanx a lot…..
Thank you!
Simply Awesome
So AWESOME!!! Not only does it work, it makes you feel like your a hacker or something when you delete somehting like WINDOWS folder lol
Thank you!
After trying everything under the sun this worked.
Genius !!
Thanks so much.
i
thas for the tip, but get an error in the DOS command shell.
This is the message (translated from Spanish)
C:\Windows\system32>TAKEOWN /f “C:\wamp” /r /d y
ERROR: Sintax nopt valid. The value “y” isn´t allowed for option “/d”.
Write “TAKEOWN /?” in order to use it.
WOW! Thanks!
Ran this for an external hard drive I had saved a windows back up to. Genius, struggled with this for hours before I came across this blog. Thank you for posting.
Hi,
It worked very well, You helped me so much.
Thank you.
Creating the delete.bat file did the trick. Thank you.
works perfectly! Many thanks
You saved me! Thank you so much! I even re-installed windows but there were unknown account permissions blocking me. This was the best help i got. I owe you one!
i already right click on the delete.bat file and select run as administrator. but i still cant delete the file i wanted to delete. help