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

Posted on 2014-07-14
Last Modified: 2014-07-16
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 ...
Question by:LGroup1
    LVL 35

    Assisted Solution

    by:Jian An Lim
    rmdir <directory> /s /q

    LVL 23

    Accepted Solution

    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..)

    LVL 24

    Assisted Solution

    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.
    LVL 23

    Expert Comment

    I hadn't thought of that Lionelmm.. that's a great tip...


    Author Closing Comment

    Great answers - thanks all !

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Redirected folders in a windows domain can be quite useful for a number of reasons, one of them being that with redirected application data, you can give users more seamless experience when logging into different workstations.  For example, if a use…
    The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
    This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…
    To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now