Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2007 Jan : Monitoring a file addition to a directory

www.cryer.info
Managed Newsgroup Archive

Monitoring a file addition to a directory

Subject:Monitoring a file addition to a directory
Posted by:"Tsourinakis Antonis" (tsoyr..@otenet.gr)
Date:Wed, 31 Jan 2007 10:48:36 +0200

I am trying to make an application to monitor a file addition on a
directory and then to read it in a string list by the LoadFromFile
Method.
This addition would be either by creating a new file or copying an
existed one to a specific directory.

I tried the copying method and these are my results:

I have succeeded so far to monitor the file addition but if size of
the file is a big one the LoadFromFile arises an exception.
First thought was that if I insert a sleep for 3 seconds then the file
addition have enough time to finish and the LoadFromFile would
succeed.
This works so far, but I tried to find a more "correct" solution.

So I tried after the monitor fires the FILE_ACTION_ADDED to
1) parse the file attributes by the FileGetAttr but I failed because
during the files addition the attributes remain the same (I hoped that
starting to finish they would change)
2) I tried using the FindFirst function checking either file size or
ftCreationTime, ftLastAccessTime, ftLastWriteTime but I also failed
because after a small change in the beginning all these remains the
same even if the file didn't finished.
I also added a timer firing every 1 second but I have no changes
either in size or times or attributes, even if the files is still
copied by the system.

Is there any help how can I be sure that a file added in directory
finished.
Antonis Tsourinakis
Piraeus-Greece)

Replies:

www.cryer.info
Managed Newsgroup Archive