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, folderActivity) iferr_return;
return maxon::OK;
static void ClearWatcher()
// clear global instance at the end
g_directoryWatch = nullptr;
MAXON_INITIALIZATION(nullptr, ClearWatcher);

Further Reading