Undeletable files are files on a computer that cannot be deleted through normal means. They are often associated with malware, spyware, or other potentially harmful programs. Users may want to delete undeletable files to free up disk space, get rid of stubborn malware, or regain full control over their system. However, Windows file permissions and attributes often prevent these files from being removed easily.
One method to force deletion of undeletable files is through the Command Prompt. Using the del and rd commands in Command Prompt gives you administrator-level permissions to delete protected system files. With some tweaks to the syntax, you can use Command Prompt to circumvent the file lock and delete undeletable files. This guide will walk through the steps to delete the most stubborn undeletable files using Command Prompt commands.
Identify Undeletable Files
Undeletable files are those that Windows prevents you from deleting through normal means. These files may be marked as in-use, locked, open elsewhere, system protected, or corrupted. Common locations for undeletable files include:
- Windows folders like Documents, Pictures, Desktop
- Temp folders
- Folders with long path names
- External devices like USB drives or memory cards
You can identify an undeletable file when you get an error trying to delete it normally. The error may say “Access is denied”, “File is in use”, or “Sharing violation”. Trying to delete the file via Command Prompt with “del” may return “Cannot delete file: Access is denied”. The file icon may also appear blank or corrupted.
Checking a file’s properties can also indicate the Read-only and System attributes are enabled, causing access issues. Overall, if Windows gives errors when attempting to delete a file through conventional methods, it likely requires specialized unlocking techniques.
Understand Risks
Deleting critical system files can lead to significant issues with your operating system. According to Quora, it is generally not recommended to delete system files as they are essential for the functioning of Windows. Removing the wrong files could lead to system instability, crashes, and data loss.
As explained on LinkedIn, deleting installation files risks losing the ability to uninstall or reinstall programs in the future. You may no longer have the original setup files required. This could make it difficult to rollback changes or modify installed software down the road.
According to Auslogics, deleting files in System32 risks permanently losing personal data, system settings, and configurations. Critical OS components stored here may become corrupted or damaged. Overall, caution should be exercised before deleting any files that Windows requires to operate smoothly.
Open Command Prompt
To access the Command Prompt and run it as an administrator on Windows, follow these steps:
On Windows 10 or Windows 8, press the Windows key or click the Windows button in the lower-left corner to open the Start menu. Type “Command Prompt” in the search box. Right-click on the Command Prompt result and select “Run as administrator” from the pop-up menu.
On Windows 7, click the Start button and type “cmd” in the search box. Right-click on “cmd.exe” and choose Run as administrator. If UAC prompts you, click Yes to approve running as admin.
Alternatively, you can use the Windows + X keyboard shortcut to open the Power User menu, then select “Command Prompt (Admin)” on Windows 8/10. On Windows 7, hit Windows+R to open the Run dialog box, type “cmd” and press Ctrl+Shift+Enter.
Running Command Prompt as an admin ensures you have full permissions to access, edit, and delete system files and registry keys.
Delete with DEL
The DEL command can be used to delete read-only or undeletable files in Windows. The basic syntax for DEL is:
DEL [/P] [/F] [/S] [/Q] [/A[[:]attributes]] names
To delete undeletable files, the key options are:
- /F – Forces deletion of read-only files.
- /S – Deletes specified files from all subdirectories.
- /Q – Quiet mode, do not ask if ok to delete on global wildcard.
For example, to force delete all read-only files in the current directory and subdirectories:
DEL /S /F /Q *.*
The /F switch forces deletion of read-only files, /S deletes in subdirectories, and /Q prevents prompting to confirm deletion of multiple files [1]. Be careful when using wildcards like *.* to avoid deleting unintended files.
Delete with RD
The RD (Remove Directory) command in Windows Command Prompt can delete folders, even ones that seem undeletable through the normal interface. RD provides more powerful delete capabilities than standard delete operations.
To use RD, open Command Prompt and navigate to the parent folder containing the troublesome folder you want to delete. Then type “rd foldername” to remove that folder, where “foldername” is the name of the folder.
RD has a couple useful options:
- Add /S to delete a folder and all its subfolders and files. For example, “rd /S foldername” will completely remove the target folder.
- Add /Q to delete the folder without prompting for confirmation. This lets you delete quicker.
So a command like “rd /S /Q foldername” will delete the “foldername” folder and everything inside it without asking for confirmation (see RD – Remove Directory – Windows CMD). This makes RD a powerful way to delete stuck folders in Command Prompt.
Delete Registry Keys
Files sometimes get locked or stuck in a ‘can’t delete’ state because they are tied to certain registry keys. You can use the REG DELETE command in the command prompt or a batch script to remove these registry keys and unlock the files.
The registry keys that commonly cause file lock issues are located at HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations
. This registry location keeps track of files that are pending deletion or renaming on reboot. If a file gets stuck here, it can prevent normal deletion.
To remove a stuck registry key to unlock a file, first identify the exact registry key path that is associated with the file. Then open an elevated command prompt and use REG DELETE "path_to_registry_key"
to remove that key. For example: REG DELETE "HKLM\System\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations\file_name"
You can also automate registry deletion on reboot by creating a .reg file that is set to run at startup and contains -
in front of the registry key path. This will schedule the key for deletion next time the system reboots.
After removing any stuck registry keys, you should then be able to successfully delete the formerly locked files using DEL, RD, or other delete commands.
Alternate Unlock Tools
There are several third-party unlocker utility programs you can use as an alternative to the built-in Windows tools for deleting locked files. Some popular options include:
IObit Unlocker – This free utility can force delete files that are being blocked with “access denied” errors. It integrates with Explorer for easy right-click deleting. However, it may not work on some system files.
Unlocker – Unlocker is another free utility that can delete locked files and folders. It claims to unlock files blocked by Windows, being used by other programs, or affected by errors. But it may struggle with deeper system file locks.
LockHunter – This paid unlocker tool advertises itself as a “foolproof file unlocker” able to force delete any blocked file. However, its batch unlocking abilities require the paid version. And like other unlockers, it may fail on core system files.
Third-party unlocker utilities can provide an easy way to delete locked files, especially by integrating into Explorer context menus. However, they may struggle with deeper Windows system file locks, so should be used with caution. The Windows Command Prompt methods give you more control and safety when deleting protected system files.
Prevent Future Locked Files
The simplest way to avoid having undeletable files is to always safely remove external drives and properly close programs before shutting down your computer. Here are some tips to prevent locked files:
Safely eject external hard drives, USB flash drives, SD cards, etc. before disconnecting them. In Windows, right-click the external drive icon and select “Eject”. Allow any background processes to finish before removing the drive.
Close all programs and files before shutting down your computer. Files may become locked if a program still has them open in the background. Press Ctrl + Alt + Delete and select Task Manager to force quit any unresponsive programs.
Add antivirus and other security software exceptions for folders that should not be scanned. Real-time scanning can sometimes cause files to remain open and become undeletable. Add exemptions under your antivirus settings.
Avoid force shutting down your computer if possible. Instead, properly shut down through the Start menu which closes all open programs and processes first. Forced restarts increase the chances of file corruption.
Check that files are not open in other programs before attempting to delete them. Close the file or program still using the file and then try deleting again.
Overall, practicing safe computing habits like properly ejecting drives, closing files, and shutting down cleanly will help prevent undeletable files in the future.
Recover Deleted Files
If you accidentally delete an important file, there are several methods you can try to recover it on Windows 10 and 11:
Use the built-in File Recovery tool. Open the Start menu, search for “File Recovery” and select the “Windows File Recovery” app. This allows you to scan for deleted files and restore them.1
Restore from previous versions. Right-click on the folder where the file was deleted and select “Restore previous versions.” You can browse and restore from available backups.2
Use third party tools like Recuva, Disk Drill, PhotoRec, or EaseUS Data Recovery Wizard to scan your drives and recover deleted files.
Act quickly and avoid writing new data to the drive, as this can overwrite deleted files making them unrecoverable.