CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    May 1999
    Location
    Sydney, Australia
    Posts
    420

    File Change Notification

    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


  2. #2
    Guest

    Re: File Change Notification

    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


  3. #3
    Join Date
    May 1999
    Location
    Sydney, Australia
    Posts
    420

    Re: File Change Notification

    Thanks, I'll try that

    Sally


  4. #4
    Join Date
    May 1999
    Location
    Atlanta, GA, USA
    Posts
    443

    Re: Sample code

    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-







  5. #5
    Join Date
    May 1999
    Location
    Sydney, Australia
    Posts
    420

    Re: Sample code

    Thanks...

    Sally


  6. #6
    Guest

    Re: File Change Notification

    Have a look at:

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

    it includes downloadable code...


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured