views:

2609

answers:

5

I'm new to windows programming and I'm trying to get notified of all changes to the file system (similar to the information that FileMon from SysInternals displays, but via an API). Is a FindFirstChangeNotification for each (non-network, non-substed) drive my best bet or are there other more suitable C/C++ APIs?

A: 

There are other ways to do it, but most of them involve effort on your part (or take performance from your app, or you have to block a thread to use them, etc). FindFirstChangeNotification is a bit complicated if you're not used to dealing with function pointers, etc, but it has the virtue of getting the OS to do the bulk of the work for you.

DannySmurf
A: 

@DannySmurf:

FindFirstChangeNotification is a bit complicated if you're not used to dealing with function pointers

He's dealing with the Win32 API! It's callback and function pointer hell! :) He has no choice but to get familiar with it.

+1 for Dave's answer. FindFirstChangeNotification is exactly what you need.

OJ
+10  A: 

FindFirstChangeNotification is fine, but for slightly more ultimate power you should be using ReadDirectoryChangesW. (In fact, it's even recommended in the documentation!)

It doesn't require a function pointer, it does require you to manually decode a raw buffer, it uses Unicode file names, but it is generally better and more flexible.

On the other hand, if you want to do what FileMon does, you should probably do what FileMon does and use IFS to create and install a file system filter.

MSN

Mat Noguchi
I went for ReadDirectoryChangesW in the end and had fun working out how to convert the buffer returned into a form I could pass back to my Java code, but it definitely does what I want.
Free Wildebeest
sry i downvoted by accident now i can't upvote
clyfe
A: 

You can use FileSystemWatcher class. Very efficient but cannot work with Network shared drives.

UBpine Inc
A: 

Actually FileSystemWatcher works perfectly with shared network drives. I am using it right now in an application which, among other things, monitors the file system for changes. (www.tabbles.net).