Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ReadDirectoryChangesW

Posted on 1998-11-20
6
Medium Priority
?
1,412 Views
Last Modified: 2013-11-20
My application watches for change in specific file using ReadDirectoryChangesW Windows NT API function. Changes include file creation and last write. I user OVERLAPPED structure woth non signalled event. The structure is passed to ReadDirectoryChangesW function which immediately returns. Then I wait on event using WaitForSingleObject. When change in waching directory occurs ReadDirectoryChangesW signals event and WaitForSingleObject exits blocking state. Then I reset event and restart watch.
My problem is second time after I reset event ReadDirectoryChangesW immediately returns signaling event so I get two changes in the same file with the same parameters despite only one actual chnage (i.e. file was added to the directory) occured.
Could some one explain to me why ReadDirectoryChangesW notifies about file change twice?
0
Comment
Question by:galkin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 1325050
I assume that the first notification is due to the 'file was added to directory' incident, whilst the second notification is related to the 'last time modified changed' incident for the directory itself...
0
 
LVL 7

Author Comment

by:galkin
ID: 1325051
Maybe, but I am actually interested in getting one notification, namely last write to file if it exists or creating file if it does not. Action filed of FILE_NOTIFY_INFORMATION structure has FILE_ACTION_MOFIFIED value in both cases. I need somehow to distinguish and omit case when time stamp chnaged.
0
 
LVL 3

Accepted Solution

by:
vinniew earned 400 total points
ID: 1325052
The problem is in the way ReadDirectoryChanges works underneath.  The NtCreateFile() function (in NTDLL.DLL) gets called twice and triggers it.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 3

Expert Comment

by:vinniew
ID: 1325053
Here are the flags for that api...

                                    FILE_NOTIFY_CHANGE_FILE_NAME      |      // filter conditions to watch for
                                          FILE_NOTIFY_CHANGE_DIR_NAME            |
                                          FILE_NOTIFY_CHANGE_ATTRIBUTES      |
                                          FILE_NOTIFY_CHANGE_SIZE                  |
                                          FILE_NOTIFY_CHANGE_LAST_WRITE      |
                                          FILE_NOTIFY_CHANGE_LAST_ACCESS      |
                                          FILE_NOTIFY_CHANGE_CREATION            |
                                          FILE_NOTIFY_CHANGE_SECURITY,



If you want to get file creation - specific notification, you can call readdirectorychanges multiple times, once for the notification of creation and once for the others, and use the event handle in WaitForMultipleObjects()... The event that triggers is the one that will have the notification you want.  E-mail your readdirectorychanges snippet to me and I can code what I'm talking about...
0
 
LVL 7

Author Comment

by:galkin
ID: 1325054
Thank's for explanation. But i need to folter only one call. My another problem with ReadDirectoryChangesW is that it locks directory. I try from Explorer to duplicate file using copy/paste in directory wached but I have an error "Sharing valuation. Source or target may be in use"
0
 
LVL 7

Author Comment

by:galkin
ID: 1325055
The problem  is ReadDirectoryChangesW with FILE_NOTIFY_CHANGE_LAST_WRITE notifies twice about change and there is no way do distinguish between chnage for instance in last write and time stampt as they are reffered in the same FILE_ACTION_MOFIFIED bit.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question