FileMonitor Manual

Table of Contents

About

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

Warning
The events observed and messages sent depend on the OS.

FileMonitor

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)
STATE
Types of CaptureDevices.
Definition: filemonitor.h:33
Definition: url.h:942
PyArena _PyASTOptimizeState * state
Definition: compile.h:99
return OK
Definition: apibase.h:2747
#define DiagnosticOutput(formatString,...)
Definition: debugdiagnostics.h:176
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:67
#define MAXON_INITIALIZATION(...)
Definition: module.h:864
@ DIRECTORY
Url is a directory, you can use GetBrowseIterator to iterate through the children.
#define iferr_scope
Definition: resultbase.h:1386
#define iferr_return
Definition: resultbase.h:1521

Further Reading