quantumfoam
quantumfoam

Reputation: 55

How to monitor file changes via Win API

I need to monitor changes of particular set of files (or just one file) and let Windows report to my application. It's likely, that most of the files will be in same directory, but I'd prefer per-file monitoring system.

I found this example http://codewee.com/view.php?idx=20 but the example monitors only special, Desktop folder.

First by calling SHGetSpecialFolderLocation, then using resultant LPITEMIDLIST in SHChangeNotifyRegister function (via SHChangeNotifyEntry struct)

I was not able to generalize it to arbitrary directory. MS Docs says that SHGetSpecialFolderLocation will not be supported in future anyway, SHGetFolderLocation should be used instead.

But again, SHGetFolderLocation is deprecated, not even mentioning it has no string/path parameter.

Is there any convenient function which takes directory path or complete file name and produces LPITEMIDLIST, which can be then sticked into SHChangeNotifyRegister?

Upvotes: 1

Views: 2917

Answers (1)

Igor Tandetnik
Igor Tandetnik

Reputation: 52471

FindFirstChangeNotification et al.

ReadDirectoryChangesW, ReadDirectoryChangesExW

SHParseDisplayName can be used to convert a file path to PIDL, for use with SHChangeNotifyRegister

Upvotes: 7

Related Questions