Delete Files That Cannot Be Deleted: Fixes That Work
In this article
If a file or folder refuses to delete, the cause is usually a locked handle, a permission conflict, or a system process using it. This article explains why files get stuck and gives step-by-step fixes that work on Windows and macOS, from simple restarts to command-line methods.
Why Files Get Stuck
Windows and macOS both prevent you from deleting a file that is currently open by a program or the operating system. The most common reasons are:
- File in use: A program (like a word processor or media player) has the file open.
- Permission restrictions: Your user account lacks the right to modify or delete the file.
- System or hidden files: Windows protects certain files even from administrators.
- Corrupted file system: Errors on the drive can make files appear undeletable.
- Malware or antivirus: Security software may lock files it is scanning.
Basic Fixes to Try First
- Close all programs: Save your work and close every open application, especially those that might use the file.
- Restart your computer: This releases all file handles. After restart, try deleting the file again.
- Run a disk check: On Windows, open Command Prompt as administrator and run
chkdsk /f. On macOS, use Disk Utility > First Aid. - Use Safe Mode: Boot into Safe Mode (Windows) or Safe Boot (macOS) to prevent third-party programs from locking the file.
Using Command Line to Force Deletion
If basic fixes fail, the command line can often delete stubborn files. On Windows, open Command Prompt as administrator and use:
del /f /q "C:\path\to\file.txt"
For folders, use:
rmdir /s /q "C:\path\to\folder"
On macOS, open Terminal and use:
rm -rf /path/to/file
Be careful: these commands permanently delete files without sending them to the Recycle Bin or Trash, and they cannot be undone.
Permission and Ownership Issues
Sometimes the file is locked because your account doesn't have permission. On Windows, right-click the file > Properties > Security > Advanced, then click "Change" next to the owner and set it to your account. Then grant yourself full control. On macOS, select the file, press Command+I, and at the bottom of the Info window, click the lock icon and change the Sharing & Permissions to "Read & Write" for your user.
Handling System and Protected Files
Windows protects system files like those in C:\Windows\System32. If you're trying to delete a file there, it's likely essential for the OS. Do not force-delete system files unless you are absolutely sure, as this can cause system instability. Similarly, macOS has System Integrity Protection (SIP) that prevents deletion of certain system files even for administrators. If you need to remove a file that is protected, you may need to disable SIP temporarily, but this is not recommended for most users.
When Malware or Antivirus is the Culprit
Malware often locks its own files to prevent removal. If you suspect an undeletable file is malicious, run a full system scan with your antivirus or Windows Defender. After the scan, try deleting the file again. If it's still locked, boot into Safe Mode with Networking and use a dedicated malware removal tool.
Third-Party Tools
There are utilities designed to unlock and delete stubborn files, such as Unlocker (Windows) or LockedFile (macOS). These tools integrate into the right-click menu and let you force-close handles. However, use them with caution: they can delete files that are in use by the operating system, which may cause crashes.
Frequently Asked Questions
Why does it say "The action can't be completed because the file is open in another program"?
This means a process is holding a handle to the file. Close all programs, then try again. If it persists, use Task Manager (Ctrl+Shift+Esc) to see which process is using the file, or restart the computer.
Can I delete a file that is in use by a system process?
It's risky. System processes are essential for Windows or macOS to run. Force-deleting such files can cause errors or crashes. Only do this if you're certain the file is not critical, and consider using Safe Mode to minimize system activity.
Why can't I delete a file even as an administrator?
Administrator accounts don't always have full control over system files. You may need to take ownership of the file first, as described above. Also, some files are protected by Windows Resource Protection, which even administrators cannot delete.
What does "You need permission to perform this action" mean?
It means your account lacks the necessary access rights. Right-click the file, go to Properties > Security, and edit the permissions to give your account full control. On macOS, check the Sharing & Permissions in the Info window.
Is it safe to use command-line deletion?
It is safe if you type the exact path and are sure you want to permanently delete the file. Double-check the path to avoid deleting the wrong file. Once deleted, the file cannot be recovered from the Recycle Bin or Trash.
Preventing Future Issues
To avoid stuck files, always close programs before deleting files, especially if they are open in an editor or player. Regularly run disk checks to prevent file system errors. If you frequently have permission issues, make sure your user account has appropriate rights to the folders you're working with.