How do I know if a file has been modified?

I want to implement the current reload of certain files. I suppose you can somehow read the last modified file time. This can be compared to the past when I downloaded this file. I would keep the latter in mind.

How do I know if a file has been modified since a certain time? The solution should work on Windows, Mac, and Linux.

Update: it seems my question raised some misinterpretations. To understand, clearly, I ask if the file was altered altogether. Using the last modified time was what first occurred to me, but I am open to any other solution! Unfortunately, I cannot afford to open each file and compare its contents, since we are talking about all the textures of a video game.

+6
source share
5 answers

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

+2
source

File system issues typically depend on the OS. Each OS has system calls and / or library functions to access this information. Windows has a GetFileTime function, Unix / Linux offers stat , which should also work on Mac. Maybe Java offers something, but something else is difficult to achieve using only the standard library. Google is your best friend.

+2
source

The QFileInfo class provides system-independent file information.

 QDateTime QFileInfo::lastModified () const 

Returns the date and time the file was last modified.

It should be portable enough, as this is the idea of ​​Qt. Windows, MacOS and Linux are officially supported.

+2
source

Use stat or fstat system calls. They give a struct stat structure that contains the modification time in st_atimespec .

0
source

Another solution would be to use inotify for Linux, or if you are in windows, maybe this will help?

Is there something like inotify on Windows?

0
source

All Articles