Thread View: borland.public.cppbuilder.nativeapi
3 messages
3 total messages
Started by Peter Elbertse
Thu, 03 Apr 2003 10:45
Is FindFirstChangeNotification half blind?
Author: Peter Elbertse
Date: Thu, 03 Apr 2003 10:45
Date: Thu, 03 Apr 2003 10:45
60 lines
3346 bytes
3346 bytes
Hi everyone,
I'm working on a Client-Server project in which I let the server download updates which will be
spread over the clients.
To monitor changes to the downloaded updates (when some silly person manually deletes one of the
update files), I created a thread to monitor the directory in which the files need to be. For this I
use the FindFirstChangeNotification API.
It works pretty good. It detects the removal of the Directory and it detects the removal of any File
within the Directory.
BUT... when I delete the Directory when it contains files, FindFirstChangeNotification doesn't
detect it.
I was pretty stumped when I found this out and have been searching through deja.com for any answers,
but couldn't find any.
Does someone has any idea what to do, or what i'm doing wrong?
Thanks in advance,
Peter Elbertse
The Source:
//===========================================================
//Check files on the creation of this thread:
CheckUpdateFiles();
//Loop while the Thread is not terminated:
do
{
//Now try to create all directories if needed:
if (!DirectoryExists( ExtractFilePath( ExpandFileName(sInternalDirectory + "\\" +
"NULL") ) ) )
ForceDirectories( ExtractFilePath( ExpandFileName(sInternalDirectory + "\\"
+ "NULL") ) );
//Set var:
ListenHandle = FindFirstChangeNotification(sInternalDirectory.c_str(), TRUE,
FILE_NOTIFY_CHANGE_FILE_NAME)
DWORD dResult = WAIT_TIMEOUT;
FindNextChangeNotification(ListenHandle);
while (dResult == WAIT_TIMEOUT && !Terminated)
{
//Listen for 10 seconds.
dResult = WaitForSingleObject(ListenHandle, 10000);
}
//We have a DWORD value. Now use it:
if (dResult == WAIT_OBJECT_0)
//Check files now:
CheckUpdateFiles();
//Close notification:
FindCloseChangeNotification(ListenHandle);
}
while (!Terminated);
//===========================================================
Re: Is FindFirstChangeNotification half blind?
Author: Nick B. Cassos
Date: Thu, 03 Apr 2003 13:33
Date: Thu, 03 Apr 2003 13:33
30 lines
2147 bytes
2147 bytes
On Thu, 3 Apr 2003 12:45:53 +0200, "Peter Elbertse" <zoetjuh@wanadoo.nl> wrote: >...I created a thread to monitor the directory in which the files need to be. For this I >use the FindFirstChangeNotification API. >It works pretty good. It detects the removal of the Directory and it detects the removal of any File >within the Directory. >BUT... when I delete the Directory when it contains files, FindFirstChangeNotification doesn't >detect it. >... First of all, you should "wait" after FindFirstChangeNotification, that is, "FindNextChangeNotification" should be in the same loop as your "wait" function (and following it). Now, regarding your problem, you should try adding a FILE_NOTIFY_CHANGE_DIR_NAME to your filter and, if this doesn't work for you, you should monitor one directory higher than the one you intend to. For example: C:\Program Files\My App\Watch Dir If you don't get all notifications of "Watch Dir" (after adding the flag mentioned above), you should monitor "My App". This is the *only* way to be notified for every change that happens to "Watch Dir" (assuming your have the proper filter). -- Nick B. Cassos
Re: Is FindFirstChangeNotification half blind?
Author: Peter Elbertse
Date: Wed, 16 Apr 2003 17:33
Date: Wed, 16 Apr 2003 17:33
31 lines
2094 bytes
2094 bytes
Thank you. Indeed I needed to check the upperlaying folder. Unfortunately, because file changes within the folder it can detect, just like deletion of the folder itself (if it's empty). I still find it a strange Windows "feature". "Nick B. Cassos" <nbc@no_spam.ath.forthnet.gr> wrote in message news:fcdo8vgf7j2clmso8bqg0e454l0jlvvrpq@4ax.com... > On Thu, 3 Apr 2003 12:45:53 +0200, "Peter Elbertse" > <zoetjuh@wanadoo.nl> wrote: > > >...I created a thread to monitor the directory in which the files need to be. For this I > >use the FindFirstChangeNotification API. > >It works pretty good. It detects the removal of the Directory and it detects the removal of any File > >within the Directory. > >BUT... when I delete the Directory when it contains files, FindFirstChangeNotification doesn't > >detect it. > >... > > > If you don't get all notifications of "Watch Dir" (after adding the > flag mentioned above), you should monitor "My App". This is the *only* > way to be notified for every change that happens to "Watch Dir" > (assuming your have the proper filter). > > -- > > Nick B. Cassos
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads