DirWatcher is a header-only c++ library for watching changes in folder using WinAPI. Process will run in background thread.
<thread>for threading<windows.h>for WinAPI calls<function>(optional, see below) for callback function
(c) 2017 by CIWH
Public domain
- (Optional) You can define some actions before including:
DIRWATCHER_FAILED_WATCH_DIR_ACTIONwill be called if setting handle is failed,DIRWATCHER_FAILED_CLOSE_HANDLE_ACTIONwill be called if closing handle failed,DIRWATCHER_DEFAULT_CALLBACK_MESSAGEwill be inserted as code for default callback,DIRWATCHER_MESSAGE_BUFFER_SIZEis message buffer size (default is 1024 bytes)DIRWATCHER_USE_STD_FUNCTIONif defined - will usestd::functioninstead of function pointer for callback
#include "path/to/this/file/dirwatcher.hpp"- Create object:
ciwh::DirWatcher watcher;
- Defaults: dir is
., non-recursive (dont watch subfolders)
-
Set callback:
watcher.setCallback([](ciwh::FileActionType type, const char* filename){ /* your code here */ }) -
Run:
watcher.start(); -
(Optional, will be called in destructor) Stop:
watcher.stop();
You can chande dir via setDir(const char* path) method, set recursive mode via setRecursive(bool b) method.
If watcher was running, it will restart.
Getters are: bool isRecursive(), bool isRunning(), const char* const getDir()