Unique file identifier in windows

Viewed 40967

Is there are way to uniquely identify a file (and possibly directories) for the lifetime of the file regardless of moves, renames and content modifications? (Windows 2000 and later). Making a copy of a file should give the copy it's own unique identifier.

My application associates various meta-data with individual files. If files are modified, renamed or moved it would be useful to be able to automatically detect and update file associations.

FileSystemWatcher can provide events that inform of these sorts of changes, however it uses a memory buffer that can be easily filled (and events lost) if many file system events occur quickly.

A hash is no use because the content of the file can change, and so the hash will change.

I had thought of using the file creation date, however there are a few situations where this will not be unique (ie. when multiple files are copied).

I've also heard of a file SID (security ID?) in NTFS, but I'm not sure if this would do what I'm looking for.

Any ideas?

5 Answers

One thing you can use for file uids is the create timestamp, just ensure when you scan the files into your program you tweak any createtimes that are the same as one already encountered so they are minutely different, as obviously a few files even on NTFS can otherwise have the same TS if they were created at the same time by a mass file copy, but in the normal course of things you won't get duplicates and tweaking will be few if any. d

Related