David
David

Reputation: 21

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

Upvotes: 2

Views: 790

Answers (3)

please delete me
please delete me

Reputation:

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

Upvotes: 2

Matteo Italia
Matteo Italia

Reputation: 126787

You may consider using the Distributed Link Tracking Service.

Upvotes: 3

Jon Purdy
Jon Purdy

Reputation: 54981

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.

Upvotes: 1

Related Questions