Ever had one of those folders that doesn't technically belong to you and -even though you've got Administrator rights- you can't delete it?

The usual way is to right-click the folder, select security, click advanced, change the owner of it and all subitems to you, then accept, then right-click and open it again so that you can grant full rights on the folder to you...

Well, say now you want to do this for a bunch of folders, say an existing Windows installation on a drive you're using from within a newer Windows installation... it's a huge pain in the gluteus maximus.

Why not Zoidberg a DOS batch file?
takeown /F %1\* /R /A
icacls %1\*.* /T /grant administrators:F
rmdir /S /Q %1

Example usage: deleteit.bat e:\windows

Note: if icacls is not available, try just cacls which also works, but first prompts you if you're sure.

permalink print article