FileMonitor Manual
The maxon::FileMonitor class can be used to watch a certain folder. If a file in that folder is changed, a delegate is called.
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) { iferr_scope ;
// 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 ;