'What is the fastest way to check if any files in a directory tree have changed?

Currently I'm checking against an XOR Checksum of the modified file time (st_mtime from fstat) for every file in the tree. I'm coupling this with the number of files found and a file size checksum (allowing overflows) to be safe but I'm quite paranoid that this can and will lead to false positives in the most extreme pathological cases.

One alternative (safe) option I am considering is keeping a manifest of every file by name and a CRC32 of the file contents. This option however is pretty slow, or slower than I would like at least for many files (lets say thousands).

So the question is, what are some tips or tricks you may have for determining whether any file has changed within a directory tree? I'd like to avoid a byte-by-byte comparison without trading away too much reliability.

Thanks very much for your suggestions.



Solution 1:[1]

You could use the "last modified on" property that files have (regardless of platform).

Simply store historical values and check historical values against current values, every so often.

boost::filesystem has a great cross platform API for reading this value.

EDIT: Specifically look at: http://www.pdc.kth.se/training/Talks/C++/boost/libs/filesystem/doc/operations.htm#last_write_time

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Will Da Silva