Unable to Delete Network Shared Folder Because Thumbs.db is in Use

Unable to Delete Network Shared Folder Because Thumbs.db is in Use

There is one common problem in network folders related to the use of the thumbnail caching by Windows File Explorer. You may notice that immediately after copying/moving the image directory in the network folder on the file server, Windows doesn’t allow you to delete or rename the directory. You could only rename or delete this folder only after a certain time (1-5 minutes).

When trying to delete this network share, the following error appeared:

 

Folder In Use
The action can’t be completed because the folder or a file in it is open in another program.
Close the file or folder and try again.

Can't delete folder because thumbs.db file is in use

The issue is related to a known issue described by Microsoft in the KB2025703  (Renaming a network folder in Windows Explorer fails with “the action can’t be completed”). The article states that sometimes the presence of a thumbs.db file with a thumbnail cache can prevent deleting or renaming network folders.

It looks like Windows is taking a while to create the thumbnail cache file.While this file is being created or updated, you cannot do anything with its parent directory until the thumbcache.dll process unlocks the thumbs.db file handle.

In this case, you can turn off the automatic generation of the thumbs.db file for network folders and drives.

Disable Thumbs.db Generation on Network Drives using GPO

To prevent Windows File Explorer from creating a hidden thumbnail cache (Thumbs.db fil)e when browsing folders, you can use a GPO.

    1. Run the local GPO editor (gpedit.msc) or create a domain GPO using the gpmc.msc console;
    2. Go to the following Group Policy section User Configuration -> Administrative Templates -> Windows Components -> File Explorer;
    3. This section has three options that allow you to manage the creating of the thumbs.db file by File Explorer:
      • Turn off the display of thumbnails and only display icons on network folders (prevents thumbs.db file from being created on shared network folder)
      • Turn off caching of thumbnails in hidden thumbs.db files
      • Turn off the display of thumbnails and only display iconsgroup policy - turn off thumbnails caching on network folders
    4. Enable all three policies by changing their values to Enabled;
  1. It remains to link the Group Policy to users (if you use domain GPOs) and update it on domain computers. To apply the policy settings immediately, run the command: gpupdate /force
If you have prevented Windows from creating a thumbnail image cache file in folders, Windows has to load the image files and generate thumbnails each time, which is resource consuming. As a result, creating thumbnails of images will take much longer (especially in case of folders containing a lot of images).

Disable Thumbs.db File Creation on Network Shares via Registry

In Home editions of Windows without the local GPO Editor, you can disable the creation of hidden thumbs.db files in shared network folders using the Registry Editor (regedit.exe).

To do it, create a new registry key Explorer under the HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\, and create a REG_DWORD parameter with the name DisableThumbsDBOnNetworkFolders and the value 1.

 

DisableThumbsDBOnNetworkFolders

The same operation can be done with a single command:

reg add "HKCU\SOFTWARE\Policies\Microsoft\Windows\Explorer" /v DisableThumbsDBOnNetworkFolders /d 0x1 /t REG_DWORD /f

Recursively Delete Thumbs.db on Shared Folder using PowerShell

The existing Thumbs.db files are not automatically removed from the shared folders after you enable the policy. You can recursively delete all Thumbs.db files on a specific drive or in a network folder using PowerShell.

Go to the folder you need (UNC paths supported):

cd \\mun-fs01\Public\Photo
To list all Thumbs.db files in subfolders, run:
Get-ChildItem -Path . -Include Thumbs.db -Recurse -Name -Force | Remove-Item –Force –WhatIF
delete thumbs.db files from network drive using powershell
Recursively delete the found thumbnail files:
Get-ChildItem -Path . -Include Thumbs.db -Recurse -Name -Force | Remove-Item –Force