Delete Files and Folders from Storage Server ('Permission or Access Denied')

A site is trying to delete a 200 GB folder (and associated files) from a network storage server, but when trying to delete many or most of the files and folders say 'Access Denied' or 'Administrator Permissions Needed' when trying to delete.  After signing on to the machine with a local and domain Admin account and attempting to take ownership of the folder and files the same message appears - and the Take Ownership process fails.  Apparently some or many of the files and folders are .NET developer-created files or copied system files.  How can one quickly and easily delete that entire folder (in one step) without having to drill down into each subfolder, reset the file and folder permissions, manually take ownership of the smaller subfolders one by one, delete, and then repeat (which seems to work but is very time consuming as there are hundreds of folders) ??  For some reason it will work at the drilled-down subfolder level but fails when attempting to do at the top folder level.  TIA ...
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jian An LimSolutions ArchitectCommented:
rmdir <directory> /s /q

Takeown.exe is your friend.  This command gives admins ownership of the files & directories recursively, and answers any prompts with a yes.  

takeown /a /f <file|directory> /r /d y /skipsl

Then you can cacls.exe against that same directory.. I just answered another article along the same lines

So, to convert it to a batch file (assuming a root/parent directory)

pushd \\server\share\<parent>
for /d %f in (*) do takeown /a /f "%f" /r /d y /skipsl
for /d %f in (*) do cacls "%f" /e /t /g administrators:f
for /d %f in (*) do attrib -s -h -r "%f" /s /d /l
for /d %f in (*) do rd /s/q "%f"

Open in new window

That should cover most circumstances.  (This is assuming you are starting with directories..)


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Lionel MMSmall Business IT ConsultantCommented:
Once you have ownership here is also another quick and easy trick--use robocopy. Create a folder, let say Del1 with nothing in it then use robocopy to mirror Del1 to the location you want to delete like this
robocopy c:\del1 \\servername\sharename /mir /s
This will get rid of everything, quick and easy.
I hadn't thought of that Lionelmm.. that's a great tip...

LGroup1Author Commented:
Great answers - thanks all !
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Server 2008

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.