How to find out if a file was modified?

danijar picture danijar · Mar 18, 2013 · Viewed 9.6k times · Source

I want to implement a live reload of certain files. I assume that it is possible to somehow read the last-modified time of a file. That could be compared against the last time I loaded that file. I would keep the latter in memory.

How can I find out whether a file was modified since a given time? The solution should work on Windows, Mac and Linux.

Update: It seems like my question has raised some misinterpretations. To make thinks clear, I am asking about finding out if a file was modified in general. Using the last-modified time was just what first came to my mind, but I am open minded to any other solution! Unfortunately I cannot afford to open each file and compare its content, since we are talking about all textures of a video game.

Answer

Andriy Tylychko picture Andriy Tylychko · Mar 18, 2013

have a look at Boost.FileSystem, std::time_t last_write_time(const path&). Disclaimer: I'm not sure how portable this concept is