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
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With