Author: Jonas Bilinkevicius
I need to monitor a series of directories, and perform a selective deletion (based
on file date) when they reach (or go over) a certain size.
Answer:
The snippet below is a procedure I wrote to monitor a directory and take action
when files are added to that directory. It uses these WinAPI functions to
accomplish that purpose:
FindFirstChangeNotification
WaitForSingleObject
FindNextChangeNotification
FindCloseChangeNotification
If you look these up in the help, you may be able to solve your problem using a
similar technique.
1 procedure TDosNotifyThread.Execute;
2 begin3 FChangeHandle := FindFirstChangeNotification(pchar(cRequestDir), false,
4 FILE_NOTIFY_CHANGE_FILE_NAME);
5 repeat6 FExitWait := WaitForSingleObject(FChangeHandle, cThreadCycleTime); {See GLOBALS}7 if FExitWait = WAIT_OBJECT_0 then8 PostMessage(MilerForm.Handle, DO_REQUEST, 0, 0);
9 FindNextChangeNotification(FChangeHandle);
10 until11 RTQ or Terminated;
12 FindCloseChangeNotification(FChangeHandle);
13 ifnot Terminated then14 Terminate;
15 end;