如何防止 Windows 资源管理器干扰删除文件夹?

发布于 2024-07-26 18:39:16 字数 332 浏览 1 评论 0原文

我有一个例程可以删除文件夹及其中的所有内容。 删除所有文件后,它所做的最后一件事是:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

别想她 2024-08-02 18:39:16

事实上,它比这更普遍。 您永远无法删除任何程序的当前目录,而不仅仅是资源管理器。

您可以编写一些东西来搜索指向感兴趣目录的资源管理器窗口,但是其他程序呢?

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?

尴尬癌患者 2024-08-02 18:39:16

以下代码显示了关闭窗口的一般方法。 此示例适用于 Internet Explorer; 你必须为 Windows 资源管理器稍微调整一下..

program Sample;

function CloseIEs(Wnd : HWnd; Form : TForm1) : Boolean; export; stdcall;
var
  sCap : array [0..255] of char;
begin
  GetWindowText (Wnd, sCap, sizeof(sCap));
  if pos ('Microsoft Internet Explorer', sCap) > 0 then
  begin
    PostMessage (Wnd, WM_CLOSE, 0, 0);
  end
  else
  begin
    // check by class name!
    GetClassName (Wnd, sCap, sizeof(sCap));
    if sCap = 'IEFrame' then
      PostMessage (Wnd, WM_CLOSE, 0, 0);
  end;

  CloseIEs := true; { next window, please }
end;

begin
  // close all hidden instances
  EnumWindows(@CloseIEs, 0);
end.

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..

program Sample;

function CloseIEs(Wnd : HWnd; Form : TForm1) : Boolean; export; stdcall;
var
  sCap : array [0..255] of char;
begin
  GetWindowText (Wnd, sCap, sizeof(sCap));
  if pos ('Microsoft Internet Explorer', sCap) > 0 then
  begin
    PostMessage (Wnd, WM_CLOSE, 0, 0);
  end
  else
  begin
    // check by class name!
    GetClassName (Wnd, sCap, sizeof(sCap));
    if sCap = 'IEFrame' then
      PostMessage (Wnd, WM_CLOSE, 0, 0);
  end;

  CloseIEs := true; { next window, please }
end;

begin
  // close all hidden instances
  EnumWindows(@CloseIEs, 0);
end.
身边 2024-08-02 18:39:16

请参阅此示例: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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文