Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Detecting file moves with ReadDirectoryChangesW

328 views
Skip to first unread message

Andrew Ward

unread,
Jan 3, 2002, 7:43:26 PM1/3/02
to
Hi,
Has anyone found a reliable way to detect file moves with
ReadDirectoryChangesW? I can receive the delete/create events fine when a
file is moved but I cannot figure out a way to determine whether it is
simply two separate files or a single file being moved because I cannot
obtain the files creation time stamp.
To make things worst the order of the events is different if the file is
being moved between folders on the same volume or between disks.

Basically what I need is to update information in a database to keep in sync
with the files if the user moves them around.

Any help appreciated
Andy

Nathan Nesbit [MS]

unread,
Jan 4, 2002, 8:46:36 PM1/4/02
to
Yuck. I don't envy your problem. To blow your mind more, think about what
happens in between calls to the API. You could miss changes. And you will
miss changes if your app isn't running.

The only way I can think of reliabily getting every file move and knowing
what is going on is to write a file system filter driver. A ton of work.

If the volume is NTFS and you are running Win2k or WinXP you can look into
the USN journal and see if that helps.

I suggest a different approach. Perhaps you can come up with a way where
you don't need to monitor for file moves and the like.

Another idea is to use object id's to tell if the file's match. Again this
requires NTFS. You would want to stick with FSCTL_CREATE_GET_OBJECT_ID to
retrieve the object id since it will assign one if it doesn't already exist.

"Andrew Ward" <a...@zfree.co.nz> wrote in message
news:#sCqPgLlBHA.2204@tkmsftngp07...

Dejan Maksimovic

unread,
Jan 7, 2002, 12:12:04 AM1/7/02
to

I have a customer (www.file-man.com), who does exactly this.
Basically, they keep the date and time of the old file name in the DB, and
on a change compare it to the new one.
They do this for Creates, too, since as you noted Move can be Copy+Delete to
a new drive.
<plug>
I suggest that you take a look at Alfa File Monitor, www.alfasp.com. It
monitors a wider range of file actions, and also provides process name, terminal
session ID and user name (if applicable, for certain actions).
AFM makes tasks such as this much easier, although not entirely codeless:-)
If you need greater precision, I can also work on a custom solution.
</plug>

Regards, Dejan.

Andrew Ward wrote:

--
Kind regards, Dejan M. www.alfasp.com
E-mail: de...@alfasp.com ICQ#: 56570367
Alfa File Monitor - File monitoring library for Win32 developers.
Alfa File Protector - File protection and hiding library for Win32 developers.
Alfa Registry Monitor - Registry monitoring library for Win32 developers.
Alfa Registry Protector - Registry protection library for Win32 developers.


0 new messages