Receiving a notification on file changes in a specific dir..

Forums for specific tips, techniques and example code
ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Receiving a notification on file changes in a specific dir..

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:46 pm

by Smeagol >> Mon, 13 Oct 2003 1:38:16 GMT

Came across the following jade script recently and thought it might be of use to others...

constants
STATUS_TIMEOUT : Integer = 258;
FILE_NOTIFY_CHANGE_FILE_NAME : Integer = 1;
FILE_NOTIFY_CHANGE_DIR_NAME : Integer = 2;
FILE_NOTIFY_CHANGE_ATTRIBUTES : Integer = 4;
FILE_NOTIFY_CHANGE_SIZE : Integer = 8;
FILE_NOTIFY_CHANGE_LAST_WRITE : Integer = 16;
FILE_NOTIFY_CHANGE_LAST_ACCESS: Integer = 32;
FILE_NOTIFY_CHANGE_CREATION : Integer = 64;
FILE_NOTIFY_CHANGE_SECURITY : Integer = 256;
vars
bResult : Boolean;
handle : Integer;
filter : Integer;
waitTime : Integer;
result : Integer;
path : String;
count : Integer;
string : String;
begin
path := 'c:\temp';
filter := FILE_NOTIFY_CHANGE_FILE_NAME;
// filter := FILE_NOTIFY_CHANGE_ATTRIBUTES;
handle := call findFirstChangeNotification(path, false, filter);
write 'Waiting with handle ' & handle.String;
waitTime := 60000;
read string;
foreach count in 1 to 10 do
result := call waitForSingleObject(handle, waitTime);
if result <> STATUS_TIMEOUT then
//
// Do your code here
//
bResult := call findNextChangeNotification (handle);
string := 'in loop';
read string;
write ' ' & app.actualTime.String & ' Result ' & result.String;
else
write ' ' & app.actualTime.String & ' Result STATUS_TIMEOUT';
endif;
endforeach;
epilog
write 'Ending with handle ' & handle.String;
bResult := call findCloseChangeNotification (handle);
end;

You'll need to have the following external functions defined too...

findFirstChangeNotification(path : String [ 256 ] io; subTree : Boolean; filter : Integer) : Integer is FindFirstChangeNotificationA in kernel32;

waitForSingleObject(handle : Integer; waitTime : Integer) : Integer is WaitForSingleObject in kernel32;

findNextChangeNotification(handle : Integer) : Boolean is FindNextChangeNotification in kernel32;

findCloseChangeNotification(handle : Integer) : Boolean is FindCloseChangeNotification in kernel32;

Return to “Tips and Techniques”

Who is online

Users browsing this forum: No registered users and 14 guests