Question

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.

Was it helpful?

Solution

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

OTHER TIPS

File-system issues are usually OS-dependent. Every OS has system calls and/or library-functions to access these information. On Windows there is GetFileTime-function, Unix/Linux offers stat, which should work for Mac, too. Maybe Java offers something, but anything else will be hard to achieve using only the standard-library. Google is your best friend.

The QFileInfo class provides system-independent file information.

QDateTime QFileInfo::lastModified () const

Returns the date and time when the file was last modified.

Should be fairly portable, since that is the whole idea of Qt. Windows, MacOS and Linux are officially supported.

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

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

Is there anything like inotify on Windows?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top