unit uNotifyChanges;
interface
uses Windows, SysUtils, Dialogs;
const
KERNEL32 = '
kernel32.dll';
FILE_NOTIFY_CHANGE_FILE_NAME = $1;
//1
FILE_NOTIFY_CHANGE_DIR_NAME = $2;
//2
FILE_NOTIFY_CHANGE_ATTRIBUTES = $4;
//4
FILE_NOTIFY_CHANGE_SIZE = $8;
//8
FILE_NOTIFY_CHANGE_LAST_WRITE = $10;
//16
FILE_NOTIFY_CHANGE_SECURITY = $100;
//256
FILE_NOTIFY_CHANGE_ALL = $7F;
//127
function RegisterDirectoryWatch (
const lpDir : PChar; bWatchSub : Boolean = False; dwFlags : DWORD = 1) :
String;
implementation
function RegisterDirectoryWatch (
const lpDir : PChar; bWatchSub : Boolean = False; dwFlags : DWORD = 1) :
String;
var
hHnd : THandle;
dwWait : DWORD;
begin
if lpDir <> '
'
then
begin
hHnd := FindFirstChangeNotification (lpDir,
bWatchSub,
dwFlags);
if hHnd = INVALID_HANDLE_VALUE
then
begin
Result := '
';
end
else
begin
while TRUE
do
begin
dwWait := WaitForSingleObject(hHnd, INFINITE);
case dwWait
of
WAIT_OBJECT_0:
begin
Result := lpDir;
Exit;
end;
end;
end;
end;
FindCloseChangeNotification(hHnd);
end;
end;
end.