title: C++ WinApi: ReadDirectoryChangesW() Receiving Double Notifications
body: <p>I try to understand <strong><code>ReadDirectoryChangesW</code></strong> function so I can be effectively informed on change of content in several directories (files overwritten, files deleted, renamed, etc..).</p>
  
  <p>One of my recent observations is, that for every file <strong>write operation</strong>, I receive always <strong>two notifications for single file</strong>. </p>
  
  <p>I traced that very carefully, and I am sure, that if I overwrite a file (say a .txt file with a new content - basically couple of extra letters inside), <code>ReadDirectoryChangesW()</code> notifies me two times per that file save. </p>
  
  <p>This is serious thing, as I expect to be notified only once per change. I do not wish to unintentionally repeat operations that should happen only once in my application.</p>
  
  <p><strong>Is this behavior known?</strong> Is there a way to receive only <strong>one notification per one change</strong>, please? Is there way to effectively <strong>avoid double notifications?</strong></p>
  
  <p>I use: </p>
  
  <ul>
  <li>Unmanaged C++</li>
  <li>Visual Studio 2012</li>
  <li>Windows 7 x64</li>
  </ul>
  
  <p>I use pretty basic code to do my tests, but you will want to see it, so here it is:</p>
  
  <pre><code>HANDLE hDir = CreateFile(
      lpDir,
      FILE_LIST_DIRECTORY,
      FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE,
      NULL, 
      OPEN_EXISTING, 
      FILE_FLAG_BACKUP_SEMANTICS, 
      NULL);
  
      int nCounter = 0;
      FILE_NOTIFY_INFORMATION strFileNotifyInfo[1024];
      DWORD dwBytesReturned = 0;   
  
      while(TRUE)
      {
          if( ReadDirectoryChangesW ( hDir, (LPVOID)&amp;strFileNotifyInfo, sizeof(strFileNotifyInfo), FALSE, FILE_NOTIFY_CHANGE_LAST_WRITE, &amp;dwBytesReturned, NULL, NULL) == 0)
          {
              ErrorCheck(_T("Reading Directory Change"));
          }
          else
          {
              _tcout &lt;&lt; _T("File Modified: ") &lt;&lt; strFileNotifyInfo[0].FileName &lt;&lt; endl;
              _tcout &lt;&lt; _T("Loop: ") &lt;&lt; nCounter++ &lt;&lt; endl;
          }
      }
  </code></pre>