
TDiskChangeNotify and TDiskChangeNotifyEx are two components that
provide notification if any changes have taken place in a folder
e.g. Files added/deleted/size or attributes changed.

Installation:
Add DiskChangeEx.pas and/or DiskChange.pas to your component gallery


TDiskChangeNotify is the simple one, only generating an event,
but not supplying any other information.

Properties:

Enabled: 	When enabled, the thread will be created and 
		changes signalled from then on. Set to true at
		runtime only.
NotifyFilter:	The filter conditions that activate the event. These
		correspond to the dwNotifyFilter parameter for the 
		Windows API function "FindFirstChangeNotification".
		Look at the D2 help on this function for more
		information.
		A note: I have found that setting the filter
		FILE_NOTIFY_CHANGE_SECURITY in Win95 results in the
		event being sent continuously (?). I did not need 
		this filter, so I did no further investigation.
WatchDir:	The directory to watch. Changing this while enabled
		is permissable.
WatchSubTree:	Include sub-directories in the watch.


Events:

OnDiskChange:	Straightforward TNotifyEvent when something happens
		in the directory that is being watched.




Now I needed a little more information about what was happening, so
TDiskChangeNotifyEx is the result (probably not complete yet). I chose
to duplicate a fair amount of code rather than inherit from 
TDiskChangeNotify. Just thought it would be easier at the time.

Properties:

Enabled:	As above.
FileExtensions:	This is a string with the extensions of files to 
		provide notification on (leave blank for ALL). The 
		find routine just does a "Pos" to see if the file
		extension fits in the string, so the format
		"*.jpg;*.gif;*.txt" or ".jpg .gif .txt" is fine.
		Wildcards in the extension will not be recognised.
		A note: in the above examples, a file with the
		extension ".jp" would also be picked up.
MaintainedDirList:	This will keep a stringlist of all files
		in the watched directory, and maintain it. This
		stringlist is public, so can be examined at any time.
		A note: Directories and sub-directories are NOT 
		recursed, so this list is only of FILES (matching
		the extensions) in the WatchDir.
		Another note: Check the public boolean "Busy" to be
		sure that this list is current.
NotifyFilter:	As above.
UseTimer:	The thing I soon discovered pretty soon was that if
		(for e.g.) three files were dropped into a 
		directory, the notify event would be fired three
		times. I therefore implemented a timer to delay the
		notification until things had settled down.
TimerDelay:	Same as TTimer.Interval
WatchDir:	As above.
WatchSubTree:	As above. Note the note for MaintainedDirList.

Events:

OnDiskChange:	As above.
OnFilesChanged:	This will generate an event that will return pointers
		to two TStringLists, one containing a list of new files
		in the directory, the other of files that have been 
		deleted.
		A note: MaintainedDirList MUST be true.
		Another note: All I wanted was a list of new and deleted
		files. If you want more detail (e.g. size and attribute
		changes) or information for sub-directories, you will
		will have to maintain a TList with the TSearchRec for
		each file and recurse sub-directories.

Public variables:

Busy:		True when the thread to find all files in a directory
		is running. 
CurrentDirList:	List of files in the watched directory. Will be valid if
		"Busy" is false.
NewFilesList:	Last reported list of new files. Will only be valid if the
		OnFilesChanged event is assigned. Will be valid if "Busy" 
		is false.
DeletedFilesList:	Last reported list of deleted files. Will only be 
		valid if the OnFilesChanged event is assigned. Will be
		valid if "Busy" is false.


The Demo:

Change the "WatchDir" property on the component to a directory on 
your drive and run. Add or delete files in that directory to see if
the component picks up the change.


Comments/suggestions/bugs/something on your mind?
e-mail me at brillacc@iafrica.com
Andrew Venmore


