Trying to delete a folder in Windows and getting an “Access Denied” error can be incredibly frustrating. This error typically occurs when you don’t have permissions to delete the folder, or the folder is currently in use by a program or service. Thankfully, there are a few ways to force delete folders in Command Prompt, even if you get the access denied message.
In this article, we’ll walk through the steps to delete a folder using CMD when you get the access denied error. We’ll cover techniques like taking ownership of the folder, unlocking it, and forcibly removing it. With the right commands, you can override the permissions and delete any folder on your system.
What Causes the “Access Denied” Error?
There are a few common reasons why you might get an access denied error when trying to delete a folder in Windows:
If your user account doesn’t have delete permissions on the folder, you’ll get the error when trying to remove it. Windows protects certain folders by default, like Program Files and Users folders. You’ll need admin rights to modify these folders.
Folder in Use
If a program is currently using files within the folder, Windows will lock the folder and prevent deletion. You may need to close any apps using the folder before deleting. Background services can also sometimes lock folders.
Incorrect Delete Command
Using the wrong delete command in Command Prompt can also lead to access denied errors. For example, the standard “del” command won’t remove locked folders. You need to use “rmdir” or “takeown” to force delete.
Corrupted Security Settings
In some cases, a folder’s NTFS security settings can become corrupted and prevent deletion. Resetting permissions and taking ownership of the folder is required to fix this.
So in summary, insufficient user rights, folder locks, wrong commands, and corrupted settings can all lead to the access denied error when trying to remove a folder in Windows.
Taking Ownership of the Folder
One method for deleting a folder you don’t have permission to remove is taking ownership of it through Command Prompt. Here are the steps:
1. Open Command Prompt as Administrator
Search for “Command Prompt” in the Windows search bar. Right-click on the top result and select “Run as Administrator”. This opens CMD with admin rights needed for taking ownership.
2. Navigate to the Folder Location
Use the CD command to change into the directory containing the folder you want to delete. For example, to navigate to the Windows folder:
3. Take Ownership of the Folder
Use the following command to take ownership, replacing “FolderName” with the name of the actual folder:
takeown /f FolderName /r /d y
The /f flag targets the folder, /r applies recursively to all child files/folders, and /d y suppresses confirmation prompts.
4. Grant Yourself Full Control Permissions
With ownership, grant your account full control permissions:
icacls FolderName /grant Administrators:F /t
This grants the built-in Administrators group, which you’re a member of, full control (/F) over the folder and all child objects (/t).
5. Try Deleting the Folder
You should now have permissions to remove the folder. Try using the “rmdir” command:
rmdir FolderName /s /q
The /s deletes child files/folders and /q suppresses confirmation prompts.
Taking ownership gives you full control to delete any folder, overcoming access denied errors.
Unlock the Folder
Sometimes folders become locked by applications or background processes. Unlocking the folder can allow its deletion. Here’s how to unlock folders in CMD:
1. Open CMD as Admin
Just like before, launch an elevated Command Prompt window to gain admin rights.
2. Navigate to Folder Location
Use cd commands to browse to the parent directory of the locked folder.
3. Unlock the Folder
Run the unlocker tool with the folder path:
This scans and unlocks files/folders at the specified location.
4. Try Deleting Again
With the folder unlocked, attempt deletion once more:
rmdir ExampleFolder /s /q
Unlocking releases any handles that could block removal. Now the folder should delete without access denied errors.
Delete Using Sub commands
If taking ownership and unlocking don’t resolve the issue, you can try forcing deletion with sub commands. These delete folders while ignoring permission errors.
1. Open Admin CMD
Launch Command Prompt as an admin again.
2. Navigate to the Folder
Use cd to browse to the troublesome folder itself rather than the parent directory.
3. Delete with Sub Commands
Try these deletion commands, each with the /q and /s flags to suppress prompts and delete sub-items:
del /f /q /s FolderName
rmdir FolderName /q /s
rd /s /q FolderName
The del /f command forcibly deletes files and folders. Rd and rmdir should now delete after taking ownership/unlocking.
4. Check Folder Status
List the folder contents after running the commands to verify deletion:
If the commands succeeded, you’ll get a “File not found” error since the folder no longer exists.
Delete on Reboot
As a last resort, you can schedule the stubborn folder to be deleted next time you reboot Windows. Here’s how:
1. Open File Explorer
Open File Explorer and navigate to the folder you want to delete. Right-click on it and select Properties.
2. Go to Security Tab
In the Properties window, click the Security tab at the top. Uncheck the box next to “Allow files in this folder to have contents indexed in addition to file properties.”
3. Confirm Delete on Reboot
Click Apply > OK, then right-click the folder again and confirm deletion on reboot. Windows will attempt to remove the folder at next startup.
4. Reboot and Check
Reboot your computer, then navigate to the folder location. It should now be gone from blocking the deletion.
This schedules the folder removal for the next reboot, when any locks should be cleared.
Being unable to delete a folder due to access denied errors can be very annoying. Thankfully, using Command Prompt provides some workarounds like taking ownership, unlocking, forced deletion, and scheduling deletion on reboot. With the right commands, you can override the permissions blocking folder removal. Just be cautious, as some system folders protect important files and registries. Back up any data before attempting force deletion methods. But for general user folders, these CMD tricks should delete access denied folders for good!
|Take Ownership||Use takeown and icacls commands to grant yourself full control permissions|
|Unlock Folder||Run unlocker tool to release folder locks|
|Force Deletion||Use del /f, rd, and rmdir with /q and /s flags to ignore errors|
|Delete on Reboot||Schedule folder deletion for next startup in File Explorer|
Additional Troubleshooting Tips
Here are some other things to try if the above methods don’t resolve the access denied error:
Disable Antivirus Temporarily
Antivirus software can sometimes block folder deletion. Try disabling temporarily.
Close Associated Programs
Check for any apps using files in the folder and close them before deleting.
Update File System Drivers
Outdated NTFS drivers can cause security issues. Update storage drivers.
Boot Into Safe Mode
Deleting in Safe Mode starts Windows with minimal drivers/services running.
Use Unlocker Software
Third-party unlocker tools like LockHunter provide a GUI to uninstall stuck folders.
Clean Up Permissions
Reset all folder permissions with tools like PermCopy or subinacl commands.
So in summary, taking ownership, unlocking folders, forced deletion, deletion on reboot, and other troubleshooting tips can help you remove folders with access denied errors in Windows. Using Command Prompt provides the most control to override folder security and removal obstructions. With the right commands, you can force delete any folder, regardless of its permissions. Just be careful when deleting system folders and always backup your data first!