views:

53

answers:

2

With ActiveState Python comes a win32api module. I need to implement something that monitors directories recursively for file-changes. Actually there's an example in the MSDN library using C. I don't know whether the win32api bindings are sufficient for something like this.

Can I import this into a Python project? Because it may be easier to write the file-alteration monitor itself in C, and to handle the results within Python. The problem is: how do I make that interact with each other.

+4  A: 

Why not try some of the python win32 examples here. It uses pywin32 and does what you want.

The "C" code that you have mentioned with link to MSDN uses FindFirstChangeNotification. Tim Golden's example uses the same through python win32 bindings. I guess this is what you want.

All windows APIs are exposed and can be utilized via pywin32.

pyfunc
Note that what that page says about `ReadDirectoryChangesW` blocking so you can't exit the loop, is not a limitation of the Win32 API. Not sure whether you can do overlapped I/O in python though.
Ben Voigt
@Ben Voigt: I guess you could using twisted framework.
pyfunc
@pyfunc: What exactly do you have in mind regarding Twisted - sounds very interesting ;)
wishi
+2  A: 

Read the documentation and try it out for yourself. win32file.FindFirstChangeNotification, etc. are there and work.

ephemient