如何检测 Win32 上的目录是否正在使用?

发布于 2024-09-12 01:40:03 字数 124 浏览 4 评论 0原文

我需要一种编程方式来了解目录(而不是文件)是否正在使用,例如因为它是在资源管理器或 CMD 提示符下打开的。如果该目录正在使用,则无法删除。目前我发现的方法是尝试重命名它,在 Windows 下是否有一种侵入性较小的方法来执行此操作?

I need a programmatic way to know if a directory (as opposed to a file) is in use, for example because it is open on explorer or a CMD prompt. If the directory is in use, then it cannot be deleted. The current way I have found to do that is trying to rename it, is there a less intrusive way to do this under Windows?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

自由范儿 2024-09-19 01:40:03

你没有指定语言,所以我假设是c++。您可以尝试使用 LockFile 自行锁定文件 或 LockFileEx,如果它返回零,则另一个进程已锁定文件。

如果另一个进程已锁定该锁,则在不终止该进程的情况下,您无法解锁该锁。

You didn't secify a language, so I am assumming c++. You can try to lock the file yourself using LockFile or LockFileEx, if it returns zero another process has the file locked already.

You can't unlock a lock if another process has it locked without terminating the process.

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