Skip to content

Instantly share code, notes, and snippets.

@nlguillemot
Created March 28, 2015 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nlguillemot/f49b730a41c934c07188 to your computer and use it in GitHub Desktop.
Save nlguillemot/f49b730a41c934c07188 to your computer and use it in GitHub Desktop.
Polling for changes in a directory
#include <Windows.h>
int main()
{
// Create a file change notification object that can be used to check for file changes.
HANDLE hNotif = FindFirstChangeNotification("C:\\Path\\To\\My\\Directory", TRUE, FILE_NOTIFY_CHANGE_LAST_WRITE);
while (1)
{
// Wait until a file change notification happens.
WaitForSingleObject(hNotif, INFINITY);
// You can use ReadDirectoryChangesW to know specifically what changed in your directory
// When you know what changed, you can automatically reload the assets corresponding to it.
OutputDebugString("A file was written somewhere inside that directory!");
// Get the notification object to start looking for the next change.
FindNextChangeNotification(hNotif);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment