Deleting Undeletable Files
The Windows NTFS file system allows the creation of paths and filenames which are very long and contain exotic characters beyond the usual ASCII character set (a, b, c, 1, 2, 3, etc). However, most of the utilities in Windows, such as Windows Explorer, and the DEL and ATTRIB commands, cannot deal with such long paths and/or characters because they filter the filenames before passing to the file system API. This means that it is possible to create files which cannot be removed, or dealt with in any other way.
Another cause of undeletable files are those with a space at the end of the filename. (When deleting a folder, if a file or folder contained in folder that has a space at the end of the name, the operation will silently quit.)
Using Robocopy To Remove Unwieldy Filenames
Robocopy, unlike many of the inbuilt commands, supports much longer paths.
- Suppose the folder containing the files to be deleted is C:\FILES.
Make another folder, and move all of the files to be retained into it, so only the files to be deleted are in C:\FILES.
- At a command prompt, type:
ROBOCOPY C:\WINDOWS C:\FILES /MIR
The /MIR command makes a mirror of the source folder into the destination folder, including removing files which are not in the source folder. Thus Robocopy will first remove all the files in C:\FILES regardless of their names or attributes, then copy the contents of C:\WINDOWS.
The Robocopy command can be cancelled with Ctrl-C almost immediately as the deletion operation will be done first.
- Remove the newly-copied files from C:\FILES and rearrange the files moved out from step 1.
Using Short Names To Remove Problematic Files
If you've identified a file or folder with a problematic filename, or one which has a space at the end:
- Open a command prompt and navigate to the root location:
- Enter a directory listing command:
This will list the files with their generated 8.3 (DOS-compatible) names:
03/06/2015 05:21 PM <DIR> SHELLE~1 shellext
- Delete the file (or remove the folder) using the short name:
- If renaming, use a temporary name first, as the corrected filename may conflict with the corrupt name:
ren SHELLE~1 TempFolder
ren TempFolder Shellext