Click to See Complete Forum and Search --> : File Change Notification


sally
April 15th, 1999, 10:14 PM
How can I make my peogram be notified by Win95/98/NT of changes to the file system, ie, file has been deleted, created, chnaged etc......?

Sally

Sally
April 15th, 1999, 10:14 PM
How can I make my peogram be notified by Win95/98/NT of changes to the file system, ie, file has been deleted, created, chnaged etc......?

Sally

April 16th, 1999, 04:07 AM
You can set up a file notification object using:

FindFirstChangeNotification ( LPCTSTR lpPathName,
BOOL bWatchSubtree,
DWORD dwNotifyFilter )

lpPathName is the name of the topmost directory you want to monitor, bWatchSubtree is TRUE if you want to monitor all sub-directories of lpPathName, and dwNotifyFilter is a set of flags which defines the types of changes you are interested in (e.g. name changes, size, or time changes).

This returns a handle that you can wait on (using WaitForSingleObject, WaitForMultipleObjects etc.). The wait terminates when any event of the types you asked to monitor. Unfortunately you don't get told what has changed: you have to go and search the directories to find this out.

When you have processed the event you can use FindNextChangeNotification if you want to go back and wait for another event, or FindCloseCHangeNotification if you are finished.

HTH

sally
April 18th, 1999, 10:18 PM
Thanks, I'll try that

Sally

Sally
April 18th, 1999, 10:18 PM
Thanks, I'll try that

Sally

Masaaki
April 18th, 1999, 11:28 PM
Hi, Sally.

According as Programming with Win95 with MFC, p968.

UINT ThreadFunc(LPVOID pParam)
{
HWND hwnd = (HWND) pParam;
HADNLE hChange = ::FindFirstChangeNotification("C:\\",
TRUE, FILE_NOTIFY_FILE_NAME | FILE_NOTIFY_DIR_NAME);

if(hChange == INVALID_HANDLE_VALUE) {
TRACE("Error: FindFisrtChangeNotification failed.\n");
return (UINT) -1;
}

while(TRUE) {
::WaitForSingleObject(hChange,INFINITE);
::PostMessage(hwnd, WM_USER, 0, 2);
::FindNextChangeNotification(hChange);
}
return 0;
}

You need worker thread to continue the check of file change.

Regards.
-Masaaki Onishi-

sally
April 19th, 1999, 03:56 AM
Thanks...

Sally

Sally
April 19th, 1999, 03:56 AM
Thanks...

Sally

April 19th, 1999, 09:01 AM
Have a look at:

http://www.relisoft.com/win32/watcher.html

it includes downloadable code...