Reputation: 375
I'm looking for a good and stable way to monitor file changes (created/deleted/renamed etc.) on a NAS (mounted as a share).
I know there's a FileSystemWatcher-Object provided by .NET, but also I heard that its not reliable on remote storage devices.
I'm thinking of polling remote devices and check those files wether they've changed (diff with previous collected file-properties) or not.
Edit: Concrete Requirements:
Are there any common techniques or best-practices to solve this?
Edit: How to uniquely identify a file?
A file can't be identified via their name (because it can change).
But is it possible to identify a file uniquely with a last-modified/created timestamp (miliseconds, in a 64bit integer) like Onkelborg suggested? Or do you have any other ideas?
Upvotes: 0
Views: 729
Reputation: 3997
You want to keep the number of directories and files quite small - you need to traverse every directory you are interested in, and get some kind of "tag" of each and every file. You need to keep a list of all files with their "tags" to have something to compare against. The "tag" could be either "last modified date" or file length, or both. (I recommend "last modified date". I don't recommend file length.)
I think you should be more specific, what's your requirements? Anything special? If not, what I wrote is what you need: Build a tree recursively, wait, build again, compare, iterate.
Upvotes: 1