DirectoryInfo.Delete(真),不删除当文件夹结构打开Windows资源管理器 [英] DirectoryInfo.Delete(True) Doesn't Delete When Folder Structure is Open in Windows Explorer
问题描述
假设我有这样一个文件夹结构:
Assuming I have a folder structure like:
C:\MyTemp
- MySubFolder
如果我试试这个用删除:
If I try to delete this using:
Dim path As String = "C:\MyTemp"
Dim di As System.IO.DirectoryInfo
di = System.IO.Directory.CreateDirectory(path)
di.CreateSubdirectory("MySubFolder")
di.Delete(True)
这工作正常, 除非我有Windows资源管理器打开的,我在看MySubFolder目录。然后我得到一个IOException的目录不是空的的 - 。单击确定驳回这一点,然后将文件夹结构不会被删除
This works fine, unless I have Windows Explorer open and I'm looking at the 'MySubFolder' directory. Then I get an IOException The directory is not empty. - clicking OK dismisses this and then the folder structure is not deleted.
我如何能得到这个正确执行的任何想法(即删除),运行此code,即使同时具有文件夹struture打开Windows资源管理器?
Any thoughts on how I can get this to perform correctly (i.e. delete), even when running this code while having the folder struture open in Windows Explorer?
推荐答案
雷蒙德陈揭示了这一主题的一些光(查看他的博客,有一个后续的后公布):
Raymond Chen sheds some light on this topic (check out his blog, there is a follow-up post announced):
The curse of the current directory
这篇关于DirectoryInfo.Delete(真),不删除当文件夹结构打开Windows资源管理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!