Click to See Complete Forum and Search --> : File events?


Johan M
May 18th, 1999, 07:47 AM
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

Franky Braem
May 18th, 1999, 08:55 AM
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.

Johan M
May 19th, 1999, 05:24 AM
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

Franky Braem
May 19th, 1999, 05:44 AM
Have you checked the FWATCH example on MSDN ?

Johan M
May 19th, 1999, 06:59 AM
I found it!
Unfortunately, it doesn't seem to compile as C++. The compiler complies on the data types.

/Johan M

Franky Braem
May 19th, 1999, 07:18 AM
You can pass a static method of your class to ReadDirectoryChangesW like I did in my CFileChangeEvent Class.