<p>The subject says it all - normally easy and cross platform way is to poll, intelligently. But every OS has some means to notify without polling. Is it possible in a reasonably cross platform way? (I only really care about Windows and Linux, but I use mac, so I thought posix may help?)</p>

[{'answer_id': 61258, 'author': 'C. K. Young', 'author_id': 13, 'author_profile': 'https://Stackoverflow.com/users/13', 'pm_score': 1, 'selected': False, 'text': '<p>I don\'t think POSIX itself has facilities for that. The closest to cross-platform I\'ve seen is <a href="http://oss.sgi.com/projects/fam/" rel="nofollow noreferrer">FAM</a>, which seems to work for Linux, BSD, and Irix, but I\'m not how easy it would be to port it to Windows and MacOS.</p>\n'}, {'answer_id': 61280, 'author': 'Matthias Winkelmann', 'author_id': 4494, 'author_profile': 'https://Stackoverflow.com/users/4494', 'pm_score': 0, 'selected': False, 'text': "<p>I believe OS X now has appropriate hooks/callbacks because they were needed for Spotlight indexing. </p>\n\n<p>On linux you'll have the additional trouble that there are multiple file systems commonly used. If you need the functionality for only a limited amount of files/directories, I'd try about actively looking for modifications at regular intervals.</p>\n"}, {'answer_id': 61283, 'author': 'aku', 'author_id': 1196, 'author_profile': 'https://Stackoverflow.com/users/1196', 'pm_score': 6, 'selected': True, 'text': '<p>Linux users can use <a href="http://en.wikipedia.org/wiki/Inotify" rel="noreferrer">inotify</a></p>\n\n<blockquote>\n  <p>inotify is a Linux kernel subsystem\n  that provides file system event\n  notification.</p>\n</blockquote>\n\n<p>Some goodies for Windows fellows:</p>\n\n<ul>\n<li><a href="http://msdn.microsoft.com/en-us/library/bb158663.aspx" rel="noreferrer">File Change Notification</a> on MSDN</li>\n<li>"<a href="http://www.relisoft.com/win32/watcher.html" rel="noreferrer">When Folders Change</a>" article</li>\n<li><a href="http://techsupt.winbatch.com/TS/T000001048F39.html" rel="noreferrer">File System Notification on Change</a></li>\n</ul>\n'}, {'answer_id': 61300, 'author': 'David Dibben', 'author_id': 5022, 'author_profile': 'https://Stackoverflow.com/users/5022', 'pm_score': 4, 'selected': False, 'text': '<p>The Qt library has a <a href="http://doc.qt.io/qt-5/qfilesystemwatcher.html" rel="nofollow noreferrer">QFileSystemWatcher</a> class which provides cross platform notifications when a file changes. Even if you are not using Qt, because the source is available you could have a look at it as a sample for your own implementation. Qt has separate implementations for Windows, Linux and Mac.</p>\n'}, {'answer_id': 61481, 'author': 'macbirdie', 'author_id': 5049, 'author_profile': 'https://Stackoverflow.com/users/5049', 'pm_score': 2, 'selected': False, 'text': '<p>There\'s <a href="https://developer.apple.com/library/archive/documentation/Darwin/Conceptual/FSEvents_ProgGuide/UsingtheFSEventsFramework/UsingtheFSEventsFramework.html" rel="nofollow noreferrer">File System Events API</a> as of Leopard.</p>\n'}, {'answer_id': 748741, 'author': 'paleozogt', 'author_id': 89218, 'author_profile': 'https://Stackoverflow.com/users/89218', 'pm_score': 0, 'selected': False, 'text': '<p><a href="http://monkey.org/~provos/libevent/" rel="nofollow noreferrer">libevent</a> or <a href="http://freshmeat.net/projects/libev" rel="nofollow noreferrer">libev</a> seem to be what you want, though I haven\'t used them.</p>\n'}, {'answer_id': 20699261, 'author': 'Zack Yezek', 'author_id': 1937375, 'author_profile': 'https://Stackoverflow.com/users/1937375', 'pm_score': 1, 'selected': False, 'text': '<p>I\'ve actually built this system before for use in a commercial C++ code base- as long as you don\'t need every weird thing under the sun, the Windows and POSIX systems have a lot of overlap you can abstract.</p>\n\n<p>POSIX: Use inotify- it is a whole system literally built for this job<br/>\nWindows: Use "change events". You have to build more of the glue and reporting yourself (all the APIs you need are available, there\'s just not the 1-stop-shopping inotify gives you).</p>\n\n<p>The common things you can detect in your "notification thread" for forwarding events are:<br/>\n1) Basically any invasive operation boost::filesystem supports, with the (possible) exception of modifying permissions. This is things like moving, creating, deleting, copying folders and files.<br/> \n2) Reads and writes to files (esp. writes). Be aware that if you\'re using async I/O the notifications can show up out-of-order.<br/>\n3) When a new volume comes in, such as somebody connecting a flash drive.</p>\n\n<p>inotify especially gives you an insane level of fine-grained control, Windows less so. With inotify you can literally monitor everything the filesystem is doing in near-real time if you really want to. I know #3 is possible with both without polling, but be aware that it can be really tricky to get it working correctly- on either system.</p>\n'}]
['https://Stackoverflow.com/questions/61253', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/699/']