How to delete Thumbs.db (it is being used by another process)

[Originally posted by] : http://stackoverflow.com/questions/25098180/how-to-delete-thumbs-db-it-is-being-used-by-another-process

I have a simple console application that I’m trying to delete a folder:

Directory.Delete(folder,true);

I got the exception of the annoying Thumbs.db

The process cannot access the file 'Thumbs.db' because it is being used by another process.

I can’t change the registry to avoid Thumbnail to process in folder

What are my options here to be able to delete the folder with everything in it?

thanks

shareedit

You can find out which process is blocking it with Unlocker. If you can’t kill that process you can mark this file or folder to be deleted right after the next boot with MoveFileEx.

[DllImport("kernel32.dll")]
public static extern bool MoveFileEx(string lpExistingFileName, string lpNewFileName, int dwFlags);

public const int MOVEFILE_DELAY_UNTIL_REBOOT = 0x4;

//Usage:
MoveFileEx(fileName, null, MOVEFILE_DELAY_UNTIL_REBOOT);

If you want to disable the creation of “Thumbs.db”-Files completely you can switch it off in the registry. Open the registry editor, navigate to HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer and set the value of NoThumbnailCache to 1. If this entry doesnt exist you simply can create it (DWORD 32).

For Win7 Professional / Ultimate the path to the entry is HKEY_CURRENT_USER\Software\Microsoft\ Windows\CurrentVersion\Explorer\Advanced and it’s name is DisableThumbnailCache.

shareedit
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s