Article View: borland.public.cppbuilder.nativeapi
Article #11684ReadDirectoryChangesW and use of the filename it provides
From: Daryl
Date: Sat, 17 Jan 2004 22:00
Date: Sat, 17 Jan 2004 22:00
46 lines
2555 bytes
2555 bytes
I am using API ReadDirectoryChagesW in conjunction with its support APIs to
monitor a directory for changes asynchronously.
I use a thread to assist in the monitoring and the IOCompletionPort notifies
that an event has occurred.
Anyway this appears to work well - How do I know? I write to a log all
events and it appears to capture all of them.
The problem is when I want to immediately use the file that has been copied,
if I say want to open and parse the file I use the following code:
char buff[1024];
ifstream ifs("full_path_to_file", ios::in);
//Check to see if file exists
if (!ifs) {
WriteToLog("File " + "full_path_to_file" + " does not exist.");
return;
}
while (!ifs.eof()) {
ifs.getline(buff, 1023, '\n');
// Process line, etc
}
My problem is that although I get notification of every file that is placed
into the monitored directory (I simply set the directory to monitor and then
drag and drop a file to it) I only get a handle to the first file (using
ifstream ifs("full_path_to_file", ios::in);). All subsequent files added to
the directory will not be processed - Why? It appears that they do not
exist in the directory (I use the full path to the file). I know this by
the statement if (!ifs) failing.
I can fix the problem by adding Sleep(250) just before the ifstream
ifs("full_path_to_file", ios::in); line in the above example.
I suppose it would appear that the notification that the file has been added
to the directory occurs before the file has actually been copied to the
directory, hence the file is not found.
How can I fix this problem without using Sleep(250)?
Thanks
daryl
Technical Details
Message-ID:
<4009b11a@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!news-out.visi.com!petbe.visi.com!ash.uu.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,a51981ecec0a9c82,start X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2004-01-17 14:08:57 PST From: "Daryl" <stockd@tpg.com.au> Newsgroups: borland.public.cppbuilder.nativeapi Subject: ReadDirectoryChangesW and use of the filename it provides Date: Sun, 18 Jan 2004 08:00:00 +1000 Lines: 48 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2462.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2462.0000 NNTP-Posting-Host: 202.7.180.81 Message-ID: <4009b11a@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1074376986 202.7.180.81 (17 Jan 2004 14:03:06 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!news-out.visi.com!petbe.visi.com!ash.uu.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail