User:Mjb/Windows folders that can't be renamed or deleted

From Offset
Jump to navigationJump to search

Generally, if a Windows folder can't be renamed or deleted, something is holding open the folder or something in it.

Here are two possible reasons:

Thumbs.db generation

Windows generates hidden Thumbs.db files in folders with thumbnail-able content. As of Windows 7 (maybe Vista, too), the OS doesn't actually need them; the files are only for compatibility with older Windows OSes and apps that make use of the files.

In Windows Vista and Windows 7, there's some kind of Explorer bug which sometimes holds these Thumbs.db files open, preventing renaming or deletion of their parent folder. It seems to mostly affect video files.

One workaround is this:

  • Temporarily change the folder view to one of the following: content, medium icons, large icons, extra-large icons. I don't know if this really works every time, though.

Another workaround which works 100% for me is to disable Thumbs.db generation with a group policy update. There are various instructions around for doing this, but this is the simplest (do it as an Administrator, and remember you have to do Run as Administrator when opening the command shell):

  • REG ADD "HKCU\Software\Policies\Microsoft\Windows\Explorer" /v "DisableThumbsDBOnNetworkFolders" /t REG_DWORD /d 1 /f

You can then check the status of the key:

  • REG QUERY "HKCU\Software\Policies\Microsoft\Windows\Explorer" /v "DisableThumbsDBOnNetworkFolders"

After disabling Thumbs.db generation, you might want to just go ahead and delete all your existing Thumbs.db files (do it from the root of each drive):

  • del /F /S /A:H Thumbs.db

Here are a couple of discussion threads related to this:

One of the posts mentions the possibility that it has something to do with SMB2 Client Redirector cache, but no one seems to have checked into this:

Incompatible filename on NTFS

NTFS allows pretty much the same range of file and folder names as Unix file systems, but you wouldn't know it because Windows APIs strictly enforce restrictions for compatibility with FAT32. Under normal circumstances, it is impossible to create a file or folder which violates the 260-character limit for its path (including volume spec and null terminator), or which begins or ends with a space, or which contains certain disallowed characters. Nevertheless, it happens.

Getting around the path depth issue is easy. Use SUBST to temporarily assign a volume (drive) letter to a directory within the path. Then you can use that drive to access and delete the content.

The illegal character issue has different solutions. Here are a few:

  • Use a question mark to match characters, e.g. del file.txt?
  • Put the space-containing name in double quotes, e.g. del "file.txt "
  • Same, but specify the path like del "\\?\C:\path\to\file.txt "
  • Do DIR /X to see the 8.3 filename, and use that.
  • Boot into Linux, mount the NTFS drive read/write, and delete/rename as needed.

See also the many suggestions at https://support.microsoft.com/en-us/help/320081/you-cannot-delete-a-file-or-a-folder-on-an-ntfs-file-system-volume