使用者工具

網站工具


program:c:how_do_i_make_my_program_watch_for_file_modification_in_c

How do I make my program watch for file modification in C++?

http://stackoverflow.com/questions/931093/how-do-i-make-my-program-watch-for-file-modification-in-c

There are several ways to do this depending on the platform. I would choose from the following choices:

Cross Platform

Trolltech's Qt has an object called QFileSystemWatcher which allows you to monitor files and directories. I'm sure there are other cross platform frameworks that give you this sort of capability too, but this one works fairly well in my experience.

Windows (Win32)

There is a Win32 api called FindFirstChangeNotification which does the job. There is a nice article which a small wrapper class for the api called How to get a notification if change occurs in a specified directory which will get you started.

Windows (.NET Framework)

Yes some people do use C++/CLI with the .NET Framework. System.IO.FileSystemWatcher is your class of choice. Microsoft has a nice article on how to monitor file system changes using this class.

OS X

The FSEvents API is new for OS X 10.5 and very full-featured.

Linux

Use inotify as Alex mentioned in his answer.

program/c/how_do_i_make_my_program_watch_for_file_modification_in_c.txt · 上一次變更: 2013/08/10 12:08 (外部編輯)