tags:

views:

117

answers:

2

I want to be able to detect whenever new files are created or existing files are modified or deleted within a given directory tree (or set of trees). The brute force way to do this would be to just rescan the tree looking for changes, but I'm looking for a more "interrupt driven" solution where the file system tells my code what changed when it changes, rather than my code having to "poll" by continuously scanning through thousands of files looking for changes.

A way to do this in Python is preferred, but if I have to write a native module in C that's ok as a last resort.

+6  A: 

pyinotify is IMHO the only way to get system changes without scanning the directory.

ebt
+4  A: 

twisted.internet.inotify! It's much more useful to have an event loop attached than just free-floating inotify. Using twisted also gives you filepath for free, which is a nice library for more easily manipulating file paths in python.

Aaron Gallagher
Also it's nice when downvoters leave a comment. Did `twisted` murder your parents or something? I don't understand the irrational hatred.
Aaron Gallagher
Downvote != hatred. Perhaps they disagree with your recommendation, but didn't feel like arguing about why? Your initial reaction to the downvote merely confirms a possible assumption that you're overly sensitive to differing opinions.
Chris
@Chris, I wouldn't say it's particularly useful to the question asker to downvote without an explanation. Also your initial reaction to my initial reaction makes me instantly suspicious that you were the downvoter.
Aaron Gallagher
@Aaron, I tended to agree w/you and was about to upvote, just to compensate the crazy unexplained downvote (which happens all the time of course), but that paranoid sentence of suspicion against @Chris made me rethink -- reinforcing any belief that feeling and expressing such paranoid suspicions is at all positive, useful, or productive, would be truly, sadly damaging.
Alex Martelli
FTR, no, I wasn't the downvoter. You will get downvotes now and then, often without explanation. Deviating from the topic to complain about it doesn't help anybody and quite frankly, looks bad.
Chris
@Alex, I was being silly. I forgot that the internet is serious business.
Aaron Gallagher
Pfft Upvoting. Perfectly good answer, and downvoting without explanation is becoming a plague here.
chiggsy
The etiquette is that if you downvote, you either leave a comment explaining the problem, or upvote an existing comment that already explains the problem.
caf
@Aaron, OK, upvoting then, since it _is_ a good answer after all. But, since there _are_ paranoids (on the net as well as elsewhere), how's one to know that you're being serious (unless, say, they happen to know you personally)? That's what emoticons are for...
Alex Martelli
FWIW: I upvoted both answers. I accepted the other one because it was more what I was looking for, but this answer at least got me to consider look into Twisted for future projects.I'm also not a fan of the "drive-by downvote" and wish people would explain their downvotes in a comment.
Laurence Gonsalves