Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find out if a file was modified?

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.

like image 374
danijar Avatar asked Mar 18 '13 13:03

danijar


People also ask

How do you check if a file has been modified in Java?

To really know if the file has changed, you'd need to store a hash of the files (md5sum, sha256, etc) and for the comparison re-hash and compare the values of the 2 hashes.


1 Answers

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

like image 130
Andriy Tylychko Avatar answered Sep 30 '22 09:09

Andriy Tylychko