This guide explains what that cryptic code means and how you can regain control when Windows blocks a deletion. Many causes trigger the message: File Explorer glitches, bad disk sectors, missing permissions, apps keeping files open, or corrupt system files.
Start with fast, safe checks. Restart Windows Explorer from Task Manager, try renaming the target folder, or remove synced items via the OneDrive web interface. These steps often let you delete folder entries without deeper repair.
If a process locks contents, a reputable unlock tool can show handles and schedule removal at reboot. For stubborn cases, open an elevated Command Prompt and use rmdir /s “PATH” or schedule CHKDSK /F on reboot to fix bad sectors.
Later sections walk through taking ownership in Security > Advanced, running DISM and SFC for system integrity, and using System Restore when recent changes cause trouble. Follow the order here for a quick, safe recovery of your data and system.
Understand the “Directory is Not Empty” error 0x80070091 in Windows
Check what’s holding that folder back before attempting repairs. The 0x80070091 code means Windows cannot remove a target folder because items remain inside, often hidden or locked.
Common causes include apps keeping a file handle open, permission or ownership mismatches, bad sectors on a drive, or corruption in system components. Third‑party antivirus can block deletes while scanning. Abrupt shutdowns or incomplete removals may leave ghost entries that resist normal cleanup.
- This message often appears in File Explorer or other file manager dialogs when a delete fails.
- In a command session, rmdir or rd returns the same text at the prompt with the path shown.
- Bad disk sectors can prevent read/write and leave partial folders that neither Explorer nor the shell can remove.
- Pausing real‑time protection or booting Safe Mode helps isolate the case when security software interferes.
Understanding which pattern matches your situation makes choosing the next step—unlocking files, repairing the disk, or restoring system files—much easier.
Quick fixes to try before advanced steps
Small resets and isolation steps can free stubborn folders fast. Try these first. They often solve the issue without running complex commands or repairs.
Restart File Explorer: Right‑click the taskbar, open Task Manager, right‑click Windows Explorer and choose Restart. After the shell restarts, try delete folder again.
- Rename then delete. Right‑click the folder and pick Rename (or press F2). A new name can break a stale handle. Then attempt removal.
- Safe Mode removal. Boot into Safe Mode so only essential services run. In that environment, try delete from File Manager to avoid third‑party interference.
- OneDrive web removal. If the folder syncs with OneDrive, sign in online and remove it there. The change will sync back and often frees the local path.
- Use an unlock tool. When a running app holds files, use a reputable tool like Unlocker to reveal handles and schedule deletion at reboot.
Method | When to use | Key steps | Risk level |
---|---|---|---|
Restart Explorer | UI glitches, shell lock | Task Manager → Restart Explorer → try delete | Low |
Rename folder | Stale references | Right‑click or F2 → rename → delete | Low |
Safe Mode | Third‑party apps blocking | Boot Safe Mode → use File Manager → delete | Low |
OneDrive web | Sync conflicts | Sign in online → delete folder → sync | Low |
Unlocker tool | Process locking files | Run tool → release handles → schedule deletion | Medium |
How to Fix the Directory is Not Empty error via Command Prompt
An administrator command session gives direct control for cleaning out a locked folder. This approach uses built‑in tools in Windows when Explorer cannot delete a path.
Open an elevated command prompt window: open Start, type Command Prompt, right‑click and choose Run as administrator. Approve the UAC prompt and you’ll see a prompt window with admin rights.
Target the exact full path and always wrap it in quotes if it contains spaces. Then run either:
- rmdir /s “C:FullPathToTarget” — removes the directory and its contents and will prompt unless /q is used.
- rd /s /q “C:FullPathToTarget” — removes trees quietly without confirmation.
If the shell reports access denied or the directory still appears nonempty, clear hidden and system flags and read‑only attributes using:
attrib -h -r -s /s /d “C:FullPathToTarget*.*”
After running attrib, retry the remove directory command. Press enter after each command and read the output carefully; messages often indicate locks, permission issues, or file system faults. If disk errors persist, schedule CHKDSK separately rather than combining commands in one line.
Resolve file locks and permission issues blocking folder deletion
If files remain locked or permissions block access, begin by securing full rights over the folder. This step often clears the most common problem without running repairs.
Take ownership and grant full control
Take ownership and give your account full control
Right‑click the folder → Properties → Security → Advanced. Select Change next to Owner, enter your Windows username, click Check Names, then OK. Apply and close.
After owning the folder, grant Full control to your account or the Administrators group. Propagate permissions to subitems so inherited protections do not keep files locked.
Use Unlocker or a similar tool to release handles
Close any editors, media players, or cloud sync apps that may hold open handles. Launch the Unlocker app as an administrator, select the folder, and review locking processes.
Choose Delete from the drop‑down or schedule removal at reboot when immediate deletion fails. If command operations still fail, open an elevated command prompt and retry using standard remove commands while in Safe Mode if needed.
Action | When to use | Key step |
---|---|---|
Take ownership | Permissions block access | Properties → Security → Advanced → Change owner → Apply |
Grant Full control | Unable to modify contents | Add account → Full control → Replace child permissions |
Close apps | Files locked by programs | Exit editors, sync clients, media players |
Unlocker tool | Persistent handles | Run as admin → select folder → release or schedule delete |
Elevated prompt | GUI and tool fail | Run administrator command prompt → using command remove |
These steps usually let you able delete the stubborn folder and return your system to normal quickly.
Repair Windows and drives that cause the error
When simple steps fail, run scans and repair commands that restore system integrity. These tools find malware, repair corrupted system files, and fix disk faults that prevent removal.
Scan for malware with Microsoft Defender
Open Windows Security → Virus & threat protection → Scan options. Choose a Full scan first.
If the folder still resists removal, run Microsoft Defender Offline scan. This catches threats that run before Windows loads.
Run DISM and System File Checker
Open an elevated command prompt. Run: DISM.exe /Online /Cleanup-image /Restorehealth
. After it finishes, run sfc /scannow
.
Wait until each utility completes. These commands repair servicing components and replace corrupt system file entries.
Check the drive with CHKDSK
In an admin command session, run CHKDSK /F C:
(swap C: for your target drive). If prompted, type Y to schedule at restart and then restart Windows.
CHKDSK runs before Windows loads and fixes bad sectors that can leave phantom contents behind.
- Rule out malware first: run a Full scan, then Offline if needed.
- Repair system: run DISM, then run the file checker.
- Repair disk: schedule CHKDSK for the affected drive and reboot.
Utility | Main purpose | Command / Steps | When to use |
---|---|---|---|
Microsoft Defender | Detect and remove malware | Windows Security → Scan options → Full or Offline scan | Suspected infections blocking file actions |
DISM | Repair servicing components | DISM.exe /Online /Cleanup-image /Restorehealth | Corrupt update or component store |
System File Checker | Restore system file integrity | sfc /scannow (run after DISM) | Missing or damaged system file entries |
CHKDSK | Repair disk errors and bad sectors | CHKDSK /F X: (replace X with drive) → schedule and restart | Drive faults, read/write failures, recurring folder issues |
Roll back recent changes and prevent future directory issues
When recent changes break normal file behavior, rolling back can restore a stable setup quickly. Use System Restore if deletes worked before a driver, update, or app install changed system state. This method preserves personal files while reverting system files and drivers.
Use System Restore to revert to a stable restore point
In Windows: open Start, search Recovery, select Open System Restore, then Next. Pick the most recent restore point and follow the prompts: Next → Finish. The computer will restart and apply the selected restore.
If Windows won’t boot: hold Shift while clicking Restart. Choose Troubleshoot → Advanced options → System Restore and follow the recovery prompts from that environment.
Best practices: proper shutdowns, updates, and storage health checks
- Shut down normally and avoid forced power-offs. That reduces incomplete writes that can leave inconsistent folders.
- Keep Windows and storage drivers current to prevent compatibility issues that affect file operations.
- Schedule periodic disk health scans and run a drive scan if you notice odd behavior.
- Back up important data so recovery steps or service on a failing drive won’t risk your files.
These precautions pair with system restore as a lasting solution and cut the chance of seeing this issue again.
Conclusion
Conclusion
Use a clear, staged path when a folder refuses removal on Windows. Start with non‑destructive moves: restart Explorer, rename the folder, then try delete folder in Safe Mode or remove it from OneDrive web if synced.
When simple steps fail, open an elevated command prompt window and run attrib -h -r -s /s /d “PATH*.*”, then rd /s /q “PATH”. Verify the path in the prompt window and press enter only after checking.
Resolve locks and permissions by taking ownership in Properties → Security → Advanced, or use a reputable unlock tool to release handles. If the problem persists, run DISM and the system file checker, scan with Microsoft Defender, and run check disk with CHKDSK /F. As a last resort, use System Restore for recovery.
Follow these steps and you’ll have a reliable, repeatable solution for this common error and a safer way to remove directory content on your computer.
FAQ
What causes the 0x80070091 message when removing a folder?
Common causes include files or apps holding locks, insufficient permissions, corrupted system files, or disk problems such as bad sectors. Cloud sync clients like OneDrive can also block removal if the folder is syncing.
Can a simple restart help when a folder won’t delete?
Yes. Restarting File Explorer or rebooting Windows often clears file locks and temporary issues. Try ending explorer.exe in Task Manager, then restart it or reboot and attempt deletion again.
How do I delete a stubborn folder using Command Prompt?
Open Command Prompt as an administrator. Use rmdir /s “C:pathtofolder” or rd /s /q “C:pathtofolder” to force remove the folder and its contents. Use attrib -s -h -r “C:pathtofile” first if hidden or read-only items block removal.
What if permissions prevent folder removal?
Take ownership and assign full control. Right-click the folder, choose Properties → Security → Advanced, change the owner to your user, then grant full control. You can also use takeown /f “C:path” and icacls “C:path” /grant %username%:F in an elevated prompt.
Will Safe Mode help delete the folder?
Yes. Booting into Safe Mode loads minimal drivers and services, which lowers the chance of locks. From Safe Mode, try deleting the folder using File Explorer or Command Prompt.
Could malware cause this removal issue?
Malware can lock or hide files. Run a full or offline scan with Microsoft Defender or a reputable antivirus to rule out infection before making deeper repairs.
How do I repair system files that might block deletion?
Run System File Checker and DISM from an elevated Command Prompt: sfc /scannow, then DISM /Online /Cleanup-Image /RestoreHealth. These commands repair corrupt system components that may affect file operations.
When should I run CHKDSK for this problem?
If disk errors or bad sectors are suspected, run chkdsk C: /f (replace C: with the drive letter). It fixes filesystem errors and can release files stuck due to disk problems. You may need to schedule it at next boot for system volumes.
Can OneDrive or other cloud services block folder deletion?
Yes. If a folder is syncing, OneDrive may prevent local deletion. Pause syncing or remove the folder from OneDrive web, then delete locally. Unsyncing the folder via OneDrive settings often frees it.
What if command-line methods still fail?
Try third-party unlock tools like Unlocker or Process Explorer to find and close file handles. As a last resort, boot from WinPE or a Linux live USB and remove the folder from outside Windows.
Is System Restore useful for this issue?
If recent changes caused the problem, rolling back with System Restore can help. Restore to a point before the issue appeared, then check whether the folder can be removed normally.
How can I prevent this from happening again?
Keep Windows updated, shut down properly, maintain healthy storage, avoid abrupt removals, and monitor sync clients. Regularly run disk checks and backups to minimize risk of corruption or locked files.