FileSystemWatcher Xojo Plugin

FileSystemWatcher.Changed Event

This event is fired when the FileSystemWatcher detects a change in one of the watched directories.

Changed(
   f as FolderItem,
   fullPath as String,
   changeFlags as Integer,
   oldFileName as String)

Parameters

f
The folder item that was changed, added, removed or renamed. Note this can in some cases be nil, so you need to check for nil. Then then you can poke around in the fullPath to see what is going on. Nil will usually come from deep nested file that has been deleted and Xojo can no longer make FolderItem instance out of the path.
fullPath
The full path of the file.
changeFlags
The change flags. This is a bit-mask, see bellow how to use the bit-mask.
oldFileName
The old name of the file, or empty string if it was not a ItemRenamed operation.

Remarks

The FolderItem in the f parameter might not exist and might be nil. If for example the message was ItemRenamed then the file might have been deleted. Use f.Exists to check if file exists if needed.

Using the bit-mask:


if BitAnd(changeFlags, FileSystemWatcher.ItemAdded) = FileSystemWatcher.ItemAdded then
    // Do something here
   
elseif BitAnd(changeFlags, FileSystemWatcher.ItemRemoved) = FileSystemWatcher.ItemRemoved then
    // Do something here
   
elseif BitAnd(changeFlags, FileSystemWatcher.ItemModified) = FileSystemWatcher.ItemModified then
    // Do something here
   
elseif BitAnd(changeFlags, FileSystemWatcher.ItemRenamed) = FileSystemWatcher.ItemRenamed then
    // Do something here
end if



Other notes:
  • If you get the ItemRenamed bit mask then the oldFileName parameter will contain the old name of the file.
  • When getting ItemRemove event, then it does not mean the file was deleted, it might mean the file was moved to trash, deleted or moved somewhere else.

    See Also

    FileSystemWatcher Class