Home c++ Tracking Change in the folder: FindfirsTChangeNotification

Tracking Change in the folder: FindfirsTChangeNotification

Author

Date

Category

wrote a function (I do not think that correctly), which tracks changes in the folder:

bool if_changes (WString Path) {
  Path + = L "\\";
  Lpwstr lpath = const_cast & lt; lpwstr & gt; (path.c_str ());
  Handle HDIR = CreateFilew (LPath,
    FILE_LIST_DIRECTORY,
    File_Share_read | File_Share_Delete | FILE_SHARE_WRITE,
    NULL
    OPEN_EXISTING,
    File_Flag_Backup_semantics | File_Flag_overLapped,
    Null);
  Byte Outbuffer [5120];
  Void * pbuf = (byte *) & amp; outbuffer;
  DWORD Infonotify;
  BOOL RESULTREADCHANGE;
  DWORD OUTSIZE = SizeOF (OutBuffer);
  Handle ReadChange;
  READCHANGE = FINDFIRSTIFCHNOTIFICATIONW (LPATH,
    True
    File_notify_change_file_name |
    File_notify_change_dir_name |
    File_notify_change_size);
  Resultreadchange = FindNextChangeNotification (READCHANGE);
  FindclosechangeNotification (READCHANGE);
  Return ResultRadchange;
}

In the main cycle of the program, the condition for the presence of changes to the folder performs quite processable actions. But for some reason the function constantly sees changes in the folder, even when they are not really not.
I used readdirectorychangesw () , but it does not continue the execution of the program, and waits for any changes in the folder when I need to check the changes and run on.
Actually the question: what did I do wrong and what to do to work as in my description?


Answer 1, Authority 100%

You misunderstand these APIs. FindNextChangeNotification () Returns the success of its execution, but no changes are not available.
Example of using MSDN: HTTPS: / /msdn.microsoft.com/ru-ru/library/windows/desktop/aa365261(v=vs.85).aspx

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions