What's the difference between ReadDirectoryChangesW() and FindFirstChangeNotification() APIs?
Asked Answered
U

1

8

I want to know any change files of the specific directory. So, I figured out ReadDirectoryChangesW() and FindFirstChangeNotification() - FindNextChangeNotification() APIs.

Then, I implemented using ReadDirectoryChangesW() function. But, I don't know the why there are FindFirst... APIs. I think that ReadDirectoryChangesW() function can do all of works of FindFirst... APIs.

What's the difference?

Unwitting answered 30/10, 2014 at 7:54 Comment(0)
Z
7

FindFirstChangeNotification:

Creates a change notification handle and sets up initial change notification filter conditions. {...} This function does not indicate the change that satisfied the wait condition. To retrieve information about the specific change as part of the notification, use the ReadDirectoryChangesW function.

ReadDirectoryChangesW:

Retrieves information that describes the changes within the specified directory. The function does not report changes to the specified directory itself.

Conclusion:

If you want to register a file listener then use FindFirstChangeNotification but keep in mind that this function DOESN'T wait for a change, in order to achieve that you need to use WaitForSingleObject AFTER registering the file listener.

If you don't care about the type of the change in the path you are listening then there is no need to use ReadDirectoryChangesW. If you need to know what is the exact change that triggered WaitForSingleObject then you need to use ReadDirectoryChangesW.

Ziegfeld answered 25/3, 2015 at 8:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.