如何删除Thumbs.db(它被另一个进程使用)

我有一个简单的控制台应用程序,我正在尝试删除一个文件夹:

Directory.Delete(folder,true); 

我得到了恼人的Thumbs.db的例外

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

我无法更改注册表以避免缩略图在文件夹中处理

我有什么选择可以删除包含所有内容的文件夹?

谢谢

您可以使用Unlocker找出阻止它的进程。 如果您无法终止该进程,则可以使用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); 

如果要完全禁用“Thumbs.db” – 文件的创建,可以在注册表中将其关闭。 打开注册表编辑器,导航到HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer并将NoThumbnailCache的值设置为1 。 如果此条目不存在,您只需创建它( DWORD 32 )。

对于Win7 Professional / Ultimate,条目的路径是HKEY_CURRENT_USER\Software\Microsoft\ Windows\CurrentVersion\Explorer\Advanced ,它的名称是DisableThumbnailCache