如何检测 Win32 上的目录是否正在使用?
我需要一种编程方式来了解目录(而不是文件)是否正在使用,例如因为它是在资源管理器或 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你没有指定语言,所以我假设是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.