how to tell if a folder has been updated or changed

is there a way using declares etc… to receive a signal if a folder has been modified?

I.e. a file added or deleted or updated.

To be used as a file sync program.

I think WFS does what you want.

Many thanks Andrew,

For any others who come here you need 2 methods and 1 property

mChangeHandles as dictionary

method 1 - which you call to add the folder to the watch list, it can also watch sub-directorys

create a method called StartWatching(f as folderitem, WatchSubDirs as boolen)

[code] Soft Declare Function FindFirstChangeNotificationA Lib “Kernel32” ( path as CString, watchSubDirs as Boolean, flags as Integer ) as Integer
Soft Declare Function FindFirstChangeNotificationW Lib “Kernel32” ( path as WString, watchSubDirs as Boolean, flags as Integer ) as Integer


// Try to start watching for changes
dim handle as Integer
if System.IsFunctionAvailable( “FindFirstChangeNotificationW”, “Kernel32” ) then
handle = FindFirstChangeNotificationA( f.AbsolutePath, watchSubDirs, FILE_NOTIFY_CHANGE_FILE_NAME + FILE_NOTIFY_CHANGE_DIR_NAME )
handle = FindFirstChangeNotificationW( f.AbsolutePath, watchSubDirs, FILE_NOTIFY_CHANGE_FILE_NAME + FILE_NOTIFY_CHANGE_DIR_NAME )
end if

if handle <> -1 then
// If we don’t have a handle map, then make one
if mChangeHandles = nil then mChangeHandles = new Dictionary

// And store this handle since we'll need it
mChangeHandles.Value( f.AbsolutePath ) = handle


second method is CheckFolder(f as folderitem) as Boolean

[code] // Check to see if this folder item has a handle in the map
dim handle as Integer
handle = mCHangeHandles.Value( f.AbsolutePath )
// If this didn’t work, then something’s wrong! Either there’s
// no map, or the folder item isn’t in it. Either way, bail out
return false

// Now that we have a handle, let’s try to see if anything’s changed
// with it
Declare Function WaitForSingleObject Lib “Kernel32” ( handle as Integer, waitTime as Integer ) as Integer
dim status as Integer
status = WaitForSingleObject( handle, 0 )

// If we’ve had a change, the status will be WAIT_OBJECT_0
Const WAIT_OBJECT_0 = &h0
if status = WAIT_OBJECT_0 then
// We’ve had a change! Reset the handle so we can use it again
Declare Sub FindNextChangeNotification Lib “Kernel32” ( handle as Integer )
FindNextChangeNotification( handle )

// And return the change
return true


// If we got here, no change has taken place!
return false

first you call startwatching(f, true) then set a timer to check if the folder has changed

if checkFolder(f) = true then
’ has been changed
’ not changed
end if

Just glanced it over in passing, you check for FindFirstChangeNotificationW then use FindFirstChangeNotificationA :slight_smile:

I’d only use the FindFirstChangeNotificationW version too.