Globally Unique IDs for files in Windows
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 th开发者_如何学Pythone 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!
You may consider using the Distributed Link Tracking Service.
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...
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.
精彩评论