如何防止 Windows 资源管理器干扰删除文件夹?
我有一个例程可以删除文件夹及其中的所有内容。 删除所有文件后,它所做的最后一件事是:
if not Windows.RemoveDirectory(pname) then
raise EInOutError.Create(SysErrorMessage(GetLastError));
不幸的是,如果我在 Windows 资源管理器中有一个打开的窗口显示该文件夹,我往往会收到错误消息。 该错误表明该文件夹不为空,但事实并非如此。 有什么办法可以覆盖这个,也许强制窗口关闭?
为了以防万一,我使用的是 Vista Home Premium 64。
I've got a routine that deletes a folder and everything in it. After deleting all the files, the last thing it does is:
if not Windows.RemoveDirectory(pname) then
raise EInOutError.Create(SysErrorMessage(GetLastError));
Unfortunately, I tend to get an error from this if I have an open window in Windows Explorer displaying the folder. The error says the folder is not empty, which is not true. Is there any way to override this, perhaps forcing the window to close?
In case it makes a difference, I'm on Vista Home Premium 64.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
事实上,它比这更普遍。 您永远无法删除任何程序的当前目录,而不仅仅是资源管理器。
您可以编写一些东西来搜索指向感兴趣目录的资源管理器窗口,但是其他程序呢?
Actually, it's even more general than this. You can never delete the current directory of ANY program, not just Explorer.
You could write something that hunted down explorer windows pointing at the directory of interest but what about other programs?
以下代码显示了关闭窗口的一般方法。 此示例适用于 Internet Explorer; 你必须为 Windows 资源管理器稍微调整一下..
The following code shows the general approach for closing windows. This example is for Internet Explorer; you'll have to tweak it a bit for Windows Explorer..
请参阅此示例:https://devblogs.microsoft.com/oldnewthing/20040720 -00/?p=38393。
下面是 Delphi 中的相同代码:http://translate.google.com/translate?prev=hp&hl=ru& js=n&u=http://transl-gunsmoker.blogspot.com/2009/05/blog-post_7575.html&sl=ru&tl=en&history_state0=
您可以使用此枚举所有窗口示例并找到在您的文件夹中打开的资源管理器窗口。 然后你可以通过发送WM_CLOSE消息来关闭它。
See this example: https://devblogs.microsoft.com/oldnewthing/20040720-00/?p=38393.
And here is the same code in Delphi: http://translate.google.com/translate?prev=hp&hl=ru&js=n&u=http://transl-gunsmoker.blogspot.com/2009/05/blog-post_7575.html&sl=ru&tl=en&history_state0=
You can enumerate all windows by using this example and find the Explorer's window, which is open at your folder. Then you can close it by sending WM_CLOSE message.