Question

It is easier to explain with example.

When 2 text editors edit the same text file in the same time, when one editor saves the file, the other one understands that it was modified and asks to do smth.

How is it possible to get a signal that a file was modified outside the program?

I am working with c++ (though I think it isn't important) and on linux. (solution for windows would be good too)

Was it helpful?

Solution

ISO-C++ does not offer this functionality, so you have to stick with what the operating system provides.

On Linux that would be inotify, on Windows you would use directory change notifications.

OTHER TIPS

① Check the timestamp of the file as close as possible before writing. If it is not what it was when you last opened this file for reading, then beware!

② You can build a checksum of the file and compare this to one you built earlier.

③ Register to a system service which informs you about file activities. This depends on the goodwill of the OS you are using; if this notification service isn't working properly, your stuff will fail. On Linux have a look at Inotify.

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