How to Delete a Stubborn Undeletable File or Folder in Windows

Many of you would have come across situations where you can’t delete a file or folder no matter how you try. This article discusses the ways to delete files or folders that are stubborn or undeletable using normal methods.

How to Delete a Stubborn Undeletable File or Folder in Windows

“File in Use” Scenario

There are umpteen software programs that help you release the lock on a file/folder by some application. Utilities like Unlocker and Process Explorer will help you forcibly close the file or folder handle and then delete the file or folder.

Before resorting to using those programs, first see if you can delete the stubborn file after logging off and logging in again, or after a restart cycle. It helps in most cases. Even better, start Windows in Safe mode and delete the stubborn file or folder. See how to Start your PC in safe mode in Windows 10 or 11.

If you want to delete the file or folder without having to restart Windows, you can use tools like Process Explorer or Unlocker. These tools help you find the program/executable is causing the problem, release the lock and delete the file.

tips bulb iconYou can also use the built-in Resource Monitor to view the offending program, but Resource Monitor can’t be used to close the file handle. For more information, see the post Find Which Process Has Locked a File Without 3rd Party Tools.

Restart Explorer Shell

File Explorer may sometimes have a lock on media files hooked up by its shell extensions generally. If that’s the case, cleanly exiting the Explorer shell will help. Here is how to cleanly terminate and restart the Explorer shell in Windows 7 through 10.

cleanly restart explorer via task manager

Note that in Windows 7 and above, the Windows “File in use” dialog will show you the name of the program using the file. All you need to do is first close the program.

file in use - showing program name locked the file

However, the program name may not be displayed in some cases, and that’s why we need tools like Unlocker, Process Explorer or Resource Monitor.

IObit Unlocker

IObit Unlocker setup adds a context menu extension for files and folders. When you right-click on a file or folder and click IObit Unlocker, it shows which program is using the target file or folder.

IObit unlocker

Unlocker also offers you these options, which are self-explanatory even for end-users:

  • Unlock
  • Unlock & Delete
  • Unlock & Rename
  • Unlock & Move
  • Unlock & Copy
  • Forced mode

You can try “Forced mode” if unlock fails in normal mode. It’s an aggressive mode wherein it terminates the related processes rather than just closing the file/folder handle.


Process Explorer

Process Explorer is an excellent tool that needs no introduction. We’ve covered Process Explorer many times in the past.

Launch Process Explorer as administrator. Use the Find option (Ctrl + F), type in the part of the file name, and press Enter.

process explorer find locked files process

You’ll see the process which is using that file. All you need to do is close the program manually, and then delete the stubborn file.

Also, Process Explorer lets you close the file handle via the lower pane view. However, exiting the program is the most preferred way.

process explorer close handle - lower pane view

MoveFile.exe from Windows SysInternals

MoveFile utility (to be run from administrator Command Prompt window) allows you to schedule move and delete commands for the next reboot.

Usage:

movefile.exe [source] [dest]

Specifying an empty destination (“”) deletes the source at boot. An example that deletes stubborn.pdf is:

Example

movefile d:\tools\stubborn.pdf ""

movefile - delete file or folder on reboot

arrow hand symbolThe MoveFile utility works not just for files, but for folders as well!

To delete (on reboot) a folder named “1” located on my desktop, I used this command:

movefile C:\Users\ramesh\desktop\1 ""

The job was perfectly completed after a restart! The MoveFile utility uses MoveFileEx API to rename or delete a file. It registers the delete or rename operation in a MULTI_STRING registry value named PendingFileRenameOperations, under the following branch:

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager

movefile pendingfilerenameoperations

During the next restart, the Session Manager performs the delete or rename task by reading the registered rename and delete commands from the PendingFileRenameOperations registry value. As you can see in the above screenshot, Windows Defender seems to have scheduled a delete operation (to get rid of a superseded driver file) after a signature update.

Download MoveFile from Windows Sysinternals.


Files or folders having reserved names or invalid characters in their names

Sample scenario:  Can’t empty Windows.old using Disk Cleanup or Storage Settings as the files in Cortana “LocalState” folder remains undeletable

IOBit Unlocker is also helpful when you’re unable to clear out the Windows.old folder (which stores the previous Windows installation files) after installing the latest Feature Update. Windows.old may sometimes be undeletable due to a problem (invalid characters in the file name) with files under the Microsoft.Windows.Cortana_cw5n1h2txyewy folder under C:\Windows.old. The complete path for the problematic folder is below:

C:\Windows.old\Users\{username}\AppData\Local\Packages\Microsoft.Windows.Cortana_cw5n1h2txyewy

cannot delete cortana localstate folder inaccessible

As you can see, the folder LocalState has a couple of dots (..) after its name, which could be preventing the folder from being deleted or accessed. Attempts to delete the folder result in the following error:

An unexpected error is keeping you from deleting the folder. If you continue to receive this error, you can use the error code to search for help with this problem.

Error 0x80004005: Unspecified error

with options to Try Again, Skip or Cancel the operation.

(or)

Location is not available

C:\Windows.old\Users..\AppData\Local\packages\Microsoft.Windows.Cortana_cw5n1h2txyewy\LocalState is unavailable. If the location is on this PC, make sure the device or drive is connected or the disc is inserted, and then try again. If the location is on a network, make sure you're connected to the network or Internet, and then try again. If the location still can't be found, it might have been moved or deleted.

cannot access cortana localstate folder inaccessible

hand point iconEasy fix: In IOBit Unlocker, choose the option Unlock & Delete after selecting the Cortana folder (or the entire Windows.old folder). This will help you completely wipe out Windows.old folder easily.


Using WinRAR to delete an invalid file or folder (easiest option)

WinRAR’s file manager can handle files and folders that have Unicode or hidden characters in the file name. Using WinRAR, you can rename or delete files or folders containing invalid characters, trailing spaces, or dots.

winrar delete stubborn file or folder

You can easily rename or delete a problematic file using WinRAR’s file manager user interface.

  • Download WinRAR and run it.
  • In WinRAR, browse the parent folder that has the problematic file or subfolder.
  • Right-click on the item and choose Rename.
  • Assign a valid name that the Windows Operating System will support.
    winrar delete stubborn file or folder

To delete a file (instead of renaming it), press Shift + Del (for permanent deletion) or Del (to send it to Recycle Bin).

Note that the Del command may not work in some cases — e.g., the file name contains invalid characters, or the file name is too long. It would ask you to use Shift + Del to delete the file.

winrar delete stubborn file or folder

So, press Shift + Del for permanent deletion, and click Yes to proceed.

winrar delete stubborn file or folder

voilà! The stubborn file/folder is now gone. Thanks to WinRAR for making the job very easy!

The case of the duplicate Windows directory

Here’s another case where a duplicate “Windows ” directory (with a trailing space) appeared after updating Windows.

Attempting to access the folder contents caused the error “Location is not available”.

duplicate windows directory - inaccessible

Attempting to delete the item via Safe mode caused the following error:

The action can't be completed because the folder or the file in it is open in another program.

duplicate windows directory - inaccessible

Looking at the timestamp in the error message, it appears as if the delete command was being executed on the real “Windows” folder instead of the duplicate “Windows ” folder, even though the user selected the duplicate Windows folder and pressed the Del key. This is a strange situation where the File ID returned by FsUtil.exe (and the Inode ID returned by WSL) were exactly the same for both folders.

A Windows user named Angelo indicated that WinRAR helped her nuke the stubborn and inaccessible “Windows ” folder. Note that the Windows Subsystem for Linux (WSL) was unable to see the duplicate Windows directory. WSL returned the same INODE for both “Windows” and “Windows ” directories.

Fortunately, the WinRAR method worked!


Deleting file names (with reserved characters) manually

If you want to wipe off those invalid files and folders manually, you can use the internal syntax “\\?\” for file or folder paths. See examples and screenshots below:



Invalid or reserved characters in the filename

You may not be able to delete a file if the file name includes an invalid name (for example, the file name has a trailing space or a trailing period or the file name is made up of a space only). To resolve this issue, use a tool that uses the appropriate internal syntax to delete the file. You can use the “\\?\” syntax with some tools to operate on these files, for example:

del "\\?\c:\path_to_file_that contains a trailing space.txt "

Src: Excerpt from Microsoft KB You cannot delete a file or a folder on an NTFS file system volume

Here’s an example where a file had a trailing space and the usual del *.* command didn’t work out. It returned the error “The system cannot find the file specified”:

stubborn file with trailing space

However, using the internal syntax (“\\?\“) and including the trailing space made deletion of the file possible.

stubborn file with trailing space

EXAMPLE: Deleting folders with reserved names or having invalid characters (such as dots and spaces) in the name.

To delete the LocalState.. folder under the Cortana Package folder, here is the path and command-line you use:

rd /s \\?\C:\Windows.old\Users\%username%\AppData\Local\Packages\Microsoft.Windows.Cortana_cw5n1h2txyewy\LocalState..\

Run that command from an administrator Command Prompt.

Another example:

Let’s say we have some invalid folders, namely Con, Conduct. and LocalState..

delete folder reserved or invalid characters in name

(Note that the word con is a reserved name, and shouldn’t be used in file or folder names.)

Attempting to access the folder with a reserved name normally (e.g., con) causes the following error:

Location is not available

path:\con is not accessible.

The handle is invalid.

the handle is invalid - invalid file or folder name

To delete the folder, we’ll now run the following command from the admin Command Prompt:

rd /s "\\?\C:\con"

The other two folders namely conduct. and LocalState.. have invalid characters (.) in the file name. Let’s run the following commands to delete those folders:

rd /s "\\?\C:\conduct."
rd /s "\\?\C:\LocalState.."

delete folder reserved or invalid characters in name

Voila! The three folders are now removed.

delete folder reserved or invalid characters in name

For more information on dealing with files containing reserved or invalid characters, see Microsoft article You cannot delete a file or a folder on an NTFS file system volume.


Incorrect NTFS Permissions

If your user account control lacks the permissions to modify a file or folder, you’ll see the “permission denied” dialog when attempting to delete it. All you need to do is take ownership of the file or folder, assign your account full control permissions before deleting the file.

You can take ownership of files/folders and assign permissions via Properties, Security tab. But some users prefer the command-line method using Takeown.exe and ICacls.exe.

Take Ownership using command-line takeown.exe

arrow hand symbolFor detailed information, see our illustrative article how to take ownership of the file(s) and folder(s) (using Takeown.exe, even recursively across sub-folders). It also describes how to assign permissions using icacls.exe. Alternately, you can launch Command Prompt under System or TrustedInstaller privileges to force delete an undeletable file or folder.

tips bulb iconRelated Tip: For easier access, you can even add “Take Ownership & Assign Full permissions” option to the right-click menu, especially if you’re going to use the option more frequently. This registry tweak does the Takeown.exe and ICacls.exe operations in one go. No need to type those commands manually!

take ownership right-click menu

File system corruption

File system corruption causes errors such as “The File or Directory is Corrupted and Unreadable” when accessing or deleting a file or folder. Running disk Error Checking or Chkdsk command ought to fix the problem.

Error Checking

Open This PC (my Computer), right-click on the drive which contains the stubborn file, and click Properties. Select the Tools menu, and click “Check”.

disk error checking windows

disk error checking windows

disk error checking windows

Clicking the Show Details link opens the relevant Event Viewer entry in the Application Log. It tells you what the problem is.

error checking - application event log error

Then proceed to repair the drive now, or on the next restart as you so prefer.

disk error checking windows

Chkdsk

Alternately, you can run Chkdsk <driveletter:> /R from an elevated Command Prompt. It asks for your consent to dismount the drive and run a scan. If you choose “N” (No), it’ll prompt for scheduling a scan at the next reboot. Click Y to continue.

chkdsk repair drive

After fixing the file system errors using disk Error checking or Chkdsk, see if you can delete the stubborn file or folder.

If you know any other interesting methods to delete files that are otherwise “undeletable”, post them in the Comments section below.


One small request: If you liked this post, please share this?

One "tiny" share from you would seriously help a lot with the growth of this blog. Some great suggestions:
  • Pin it!
  • Share it to your favorite blog + Facebook, Reddit
  • Tweet it!
So thank you so much for your support. It won't take more than 10 seconds of your time. The share buttons are right below. :)

Ramesh Srinivasan is passionate about Microsoft technologies and he has been a consecutive ten-time recipient of the Microsoft Most Valuable Professional award in the Windows Shell/Desktop Experience category, from 2003 to 2012. He loves to troubleshoot and write about Windows. Ramesh founded Winhelponline.com in 2005.

9 thoughts on “How to Delete a Stubborn Undeletable File or Folder in Windows”

  1. I had a folder where none of these options worked. The folder ownership permissions were such that even an administrator could not change them or delete the folder. What did then work was to create a new dummy user, log in as the user and transfer the folder into the users documents area, then log out and log back in with an administrator account and delete the user. In some cases the folder is then deleted, in others the folder was still there in the users documents area, but could now be deleted by the administrator.

    Reply
  2. Thanks, the first solution worked perfectly for me. The solution mentioned in “Error checking”, then “repair this drive” section. Thanks again for your help.

    Reply
  3. I have a problem deleting a folder. I choose to update my AMD-drivers but it gave an error-message. After that I uninstalled all AMD-software and tried to delete the C:\AMD folder manually before installing all fresh. But it can’t. There is a subfolder C:\AMD\AMD_Radeon_Installer_21.5.2 which cannot be removed or changed. Not even with all above methods. Windows error scanning finds not any problem on the drive. I even changed all permissions of the C:\AMD folder to myself but the security of the Radeon_Installer map cannot be displayed because there aren’t any. When I create a text file next to the Radeon_Installer folder with the same name, remove the .txt extention, then I can remove the undeletable folder, but then immediately my text-file change into the folder again which again can’t be removed because it doesn’t exist. Never seen this before! And as long the C:\AMD folder can’t be removed I don’t dare to install a new driver package. Manually deleting all links to C:\AMD\* in the RegEditor and disable my antivirus and firewall also didn’t help.

    Reply
  4. If none of these works I’ve found a solution on some forum (very specific scenario):
    Create a folder with the same path as the folder where a file is.
    Eg. path is: E:\Some\Dir\file.txt
    Then using cmd create a folder “Dir” in E:\Some. In command line:
    E:\Some>mkdir Dir
    Windows will tell that the folder exists, but anyway after that operation file can be deleted. This is a very specific scenario though. Using admin cmd, safe mode, chkdsk etc didn’t work.

    Reply
  5. Thank YOU for IObit UNlocker

    I have attempted lots of methods to this stubborn File
    &
    IObit UNlocker worked quickly & smoothly

    Thanks Again

    COOP

    Reply

Leave a Reply to William Cancel reply