Windows 中文件的全局唯一 ID
我想知道如何在 Windows(XP、Vista 和 7)中获取文件和文件夹的全局唯一 ID,并且仅通过 ID 即可获取文件或文件夹的完整路径,例如 getFileByGUID。我正在尝试用 C++、C# 和 PHP 来实现这一点。
即使文件被移动,全局唯一 ID 也应保持不变,因此使用文件或文件夹的完整路径不起作用。
任何帮助将不胜感激,谢谢!
I'm wondering how to get globally unique IDs for files and folders in Windows (XP, Vista and 7), and also be able to get the full path of the file or folder just by having the ID, something like getFileByGUID. I'm trying to do this in C++, C# and PHP.
The globally unique IDs should stay the same even if the file is moved, so using the full path of the file or folder wouldn't work.
Any help would be much appreciated, thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以考虑使用分布式链接跟踪服务。
You may consider using the Distributed Link Tracking Service.
遵守
BY_HANDLE_INFORMATION 页面中提到的注意事项
,GetFileInformationByHandle
可能会有所帮助,具体取决于目标是什么。不过,这不会让人检索到文件名。由于 NTFS 硬链接,同一文件内容可能有多个路径......
Subject to the caveats mentioned in the page for
BY_HANDLE_INFORMATION
,GetFileInformationByHandle
might be helpful, depending on what the goal is.This won't let one retrieve the file's name, though. Due to NTFS hard links there may be more than one path to the same file contents anyway...
您可以将有关文件的信息(例如其元数据和/或内容)散列在一起。在整个文件系统上执行此操作而不发生冲突是很困难的,但我假设您并没有尝试对整个文件系统进行索引。不过,如果您需要文件在修改后保留其 ID,则此方法将不起作用。
You could hash together information about the file, such as its metadata and/or contents. It would be difficult to do this on an entire file system without collisions, but I assume you're not trying to index the whole file system. This wouldn't work if you need files to retain their IDs if they're modified, though.