I assume the file format isn't under your control (otherwise, generatea UUID and store it there).
File Object ID's
NTFS supports object ID's on the file level, see FSCTL_CREATE_OR_GET_OBJECT_ID. I haven't used them to be able to recommend them, but it seems like a promising thing to explore.
As with alternate data streams (below), they can get lost when copying to a non-NTFS-medium ("usual" memory sticks, CD's, DVD's, flash cards, possibly even some USB disks. ...). Also, some applications might mess up when they recreate the file when saving.
Distributed Link Tracking Service
Distributed Link Tracking Service uses file object ID's for, well, tracking links to files, and repairing them when the file is moved.
AFAIK Distributed Link Tracking Service requires a domain controller for the server. Again, I have no practical experience with this.
On NTFS, you could also create and store a UUID in an alternate data stream.
Caveats:
- Only available on NTFS, will not "survive" on other file systems
- One white paper "the future of NTFS" considered killing them, but I fancy the thought there were some other features that could help you (unfortunately, I failed to dig that out)
- I wouldn't want to create that for thousands of files of unknown origin and purpose. Though they "just work" on the file system level, some applications might mess up.
Some document formats - such as Office - allow custom document properties.
That's obviously limited, but similar mechanisms can be piggybacked onto other file types as well. (e.g. many image formats would allow adding / rewriting "custom" chunks that should be ignored by readers)
FileFromID vs. IDFromFile
Alll solutions except DLTS only allow IDFromFile
lookup, i.e. locating a file that has moved (or was deleted) requires searching all potential drives.
For DLTS, if there's no "direct API" way, you could store a DLTS-enabled shortcut in an application-specific folder, and ~~hope for~~ expect the service to repair the shortcut when the file is moved.