CFileSystemWatcher - Watch a folder for file changes. The .NET framework has a very cool object called FileSystemWatcher that listens to the file system change notifications and raises events when a directory, or file in a directory, changes. Although Windows has an API ReadDirectoryChangesW which does the same thing this function is not available in all versions of Windows (only 2000/XP). This class monitors a directory for changes using an API call available on all Windows versions: FindFirstChangeNotification. Internally it keeps a list of all files in that directory and compares the properties of these files when a change notifcation occurs. A message is sent to the owner of the CFileSystemWatcher class when something has changed:
WM_FILE_CREATED - A file has been created (WPARAM: filename)
WM_FILE_CHANGED - A file has been changed (WPARAM: filename, LPARAM: 0=creation time changed, 1=last access time changed, 2=modified time changed, 3=size changed)
WM_FILE_DELETED - A file has been deleted (WPARAM: filename)
Download demo executable
Download source code This class is part of the Pablo Software Solutions MFC Extension Package - Classes Edition
|