FileMonitor Manual

Table of Contents


The maxon::FileMonitor class can be used to watch a certain folder. If a file in that folder is changed, a delegate is called.

The events observed and messages sent depend on the OS.


maxon::FileMonitor::WatchDirectory() is used to watch the given folder.

// This example shows how to use maxon::FileMonitor to watch a given folder.
// global instance of FileMonitorItemRef
maxon::FileMonitorItemRef g_directoryWatch;
// ------------------------------------------------------------
// This function watches the given folder.
// ------------------------------------------------------------
static maxon::Result<void> WatchFolder(const maxon::Url& url)
// check argument
if (url.IoDetect() != maxon::IODETECT::DIRECTORY)
return maxon::IllegalArgumentError(MAXON_SOURCE_LOCATION);
// lambda function called when a file is was changed
auto folderActivity = [](const maxon::Url& watched, const maxon::Url& updated, maxon::FileMonitor::STATE state)
DiagnosticOutput("Some change in folder @.", watched);
// watch folder and store FileMonitorItemRef
g_directoryWatch = nullptr;
g_directoryWatch = maxon::FileMonitor::WatchDirectory(url, false, folderActivity) iferr_return;
return maxon::OK;
static void ClearWatcher()
// clear global instance at the end
g_directoryWatch = nullptr;
MAXON_INITIALIZATION(nullptr, ClearWatcher);
static MAXON_METHOD Result< FileMonitorItemRef > WatchDirectory(const Url &url, Bool watchSubtree, Observer &&observer)
Types of CaptureDevices.
Definition: filemonitor.h:33
Definition: url.h:942
PyArena _PyASTOptimizeState * state
Definition: compile.h:99
return OK
Definition: apibase.h:2667
#define DiagnosticOutput(formatString,...)
Definition: debugdiagnostics.h:176
Definition: memoryallocationbase.h:67
Definition: module.h:785
Url is a directory, you can use GetBrowseIterator to iterate through the children.
#define iferr_scope
Definition: resultbase.h:1374
#define iferr_return
Definition: resultbase.h:1465

Further Reading