CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: File events?

  1. #1
    Join Date
    May 1999
    Location
    L.A.
    Posts
    20

    File events?

    I have written two programs:
    1) One program which creates files and saves them on another computer in the network.
    2) One program which waits for files to be saved on the local HD ( typically "C:\" ) at a specified folder
    ( perhaps "work\jobs\" ).

    The two programs runs on different computers in the local network. When a file is saved, it should be
    processed by the second program.

    Ofcourse this could be solved if the second program checked the folder contents at specified times with
    a fixed time intervall. But this solution does not feel "efficient".

    * Is it possible to wait for some kind of file events, which is fired if a file is saved to a HD?
    I have not found any suggestions of this in the MSDN library.

    * If this is not possible, is there an easy and efficient way the first program can "tell" the second program
    that a file has been saved on the HD?

    Thanks in advance,
    Johan M


  2. #2
    Join Date
    May 1999
    Location
    Antwerp, Belgium
    Posts
    136

    Re: File events?

    I've created a class to watch changes for files. It notifies the derived class when files are created, modified or deleted. You could modify this class to view all changes in that directory.
    See for more information to CFileChangeEvent-class in the Misc category.

    Hope this helps.

    Franky.


  3. #3
    Join Date
    May 1999
    Location
    L.A.
    Posts
    20

    Re: File events?

    Now I have found out a little more. The function ReadDirectoryChangesW seems to be
    a good alternative for me. Unfortunately, I have not all information needed to use it ( no access
    to a good example).

    First, I know that I need to get the filehandle of the directory. This might be done by:

    char *dir_name = "C:/MyTestDir";

    HANDLE dir_handle = CreateFile(dir_name,
    FILE_LIST_DIRECTORY,
    FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
    NULL,
    OPEN_EXISTING,
    FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED,
    NULL);



    The call to ReadDirectoryChangesW() should then look something like this:

    int result = ReadDirectoryChangesW(dir_handle, ...);



    How do I use ReadDirectoryChangesW? I want it to call a method in the
    same class as a file change occurs.

    /Johan M


  4. #4
    Join Date
    May 1999
    Location
    Antwerp, Belgium
    Posts
    136

    Re: File events?

    Have you checked the FWATCH example on MSDN ?


  5. #5
    Join Date
    May 1999
    Location
    L.A.
    Posts
    20

    Re: File events?

    I found it!
    Unfortunately, it doesn't seem to compile as C++. The compiler complies on the data types.

    /Johan M


  6. #6
    Join Date
    May 1999
    Location
    Antwerp, Belgium
    Posts
    136

    Re: File events?

    You can pass a static method of your class to ReadDirectoryChangesW like I did in my CFileChangeEvent Class.


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