Win32 C ++ ReadDirectoryChangesW "create" and "modify" file difference detection?

Here is the problem: I am tracking the directory using the Win32 API ReadDirectoryChangesW . And I need to distinguish between newly created files and modified files. But there are problems ... as always :(

Cases:

  • I am tracking the directory for new / change ( FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_SIZE). Problem: After creating a file, the event of a new file event + file change is triggered. But I only need one. How can i avoid this? When the file is modified, I get what I want :).
  • I control the directory for the new file only ( FILE_NOTIFY_CHANGE_FILE_NAME) - NOT A PROBLEM.
  • I control the directory for change file ( FILE_NOTIFY_CHANGE_SIZE) only. Problem: . When a new file, the change action is activated along with the file creation event. How can i avoid this?

Of course, I applied some workarounds. But I want to know if there is any elegant way to solve the problems that I described.

Thanks in advance!

+3
source share
1 answer

You must catch FILE_NOTIFY_CHANGE_LAST_WRITE, not FILE_NOTIFY_CHANGE_SIZE, for the modified file. Files can be resized without resizing.

, , , 1-2 . , , , , .

ReadDirectoryChanges winapi. , ; , FILE_NOTIFY_CHANGE_LAST_WRITE , , , , . , , .

+4

Source: https://habr.com/ru/post/1770610/


All Articles