simplefilewatcher - Simple, cross platform, object-oriented, file watcher and notifier library. - Google Project Hostingしかもマルチプラットフォームでビルド出来て、さらに他のライブラリに依存しないのでとてもポータブル。
SimpleFileWatcher is a C++ wrapper for OS file monitoring systems. Currently it uses Win32 ReadDirec...
https://code.google.com/p/simplefilewatcher/
Windows でも inotify を意識せずにコーディング出来ます。
今日はこれと C++ で GNTP Growl する gntppp を使って、あるフォルダ配下のファイルが変更されたら Growl するアプリケーションを作ってみました。
コンパイルには、Crypto++ と、boost が必要です。
mattn/gntppp - GitHub
GNTP++: gntp client library writen in C++
https://github.com/mattn/gntppp
Crypto++ Library 5.6.1 - a Free C++ Class Library of Cryptographic Schemesコードはとてもシンプル!
Crypto++ Library is a free C++ class library of cryptographic schemes. Currently the library contains the following algorithms
http://www.cryptopp.com/
#include <FileWatcher/FileWatcher.h>
#include <gntp.h>
#include <iostream>
using namespace CryptoPP;
using namespace CryptoPP::Weak1;
gntp* client;
class UpdateListener : public FW::FileWatchListener {
public:
  UpdateListener() {}
  void handleFileAction(
    FW::WatchID watchid,
    const FW::String& dir,
    const FW::String& filename,
    FW::Action action) {
      client->notify<DES, MD5>("changed", "File Changed", filename.c_str());
    }
};
int
main(int argc, char **argv) {
  if (argc != 2) {
    std::cerr << "usage: " << argv[0] << " [directory]" << std::endl;
    return -1;
  }
  FW::FileWatcher fileWatcher;
  client = new gntp("file change notifier", "");
  client->regist<DES, MD5>("changed");
  try {
    FW::WatchID watchID = fileWatcher.addWatch(
      argv[1], new UpdateListener(), true);
    while(1) {
      fileWatcher.update();
    }
  } catch(std::exception& e) {
    std::cerr << "Exception has occurred: " << e.what() << std::endl;
  }
  return 0;
}
簡単ですね!mingw32 だと以下の様にコンパイルします。
g++ -g -fpermissive -Iinclude -I.
    source/FileWatcher.cpp source/FileWatcherWin32.cpp
    filechangenotifier.cpp
    -lcryptopp -lws2_32
    -lboost_thread-mgw47-mt-1_50 -lboost_system-mgw47-mt-1_50
※実際は1行実行してファイルを置いてみる...
おぉ...
ちょっとしたツールを作るには便利ですね。MITなので業務でも使えそうです。

 
 
 

 
 
  
 
