def __init__(self): self.init_notify_icon() watcher = FileSystemWatcher() watcher.Path = this_dir watcher.Changed += self.show_notification watcher.Created += self.show_notification watcher.Deleted += self.show_notification watcher.EnableRaisingEvents = True
# set up directory watcher to automatically reload def _watcher_reload(source, event): if event.Name in ("commands.py", "config.py", "events.py"): error = None try: _reload() except IOException: # file can still be held by write process and reload fails - retry _watcher_reload(source, event) except SyntaxError, e: if "The process cannot access the file" in str(e): _watcher_reload(source, event) else: error = e except Exception, e: error = e if error: print "reload error: %s" % error _watcher = FileSystemWatcher() _watcher.Path = Directory.GetCurrentDirectory() _watcher.Changed += _watcher_reload _watcher.EnableRaisingEvents = True if __name__ == "__main__": import run
from System.IO import FileSystemWatcher, Path from System.Threading import Thread from UdpSender import UdpSender, port, group directory = Path.GetDirectoryName(Path.GetFullPath(__file__)) dataFile = 'data.txt' watcher = FileSystemWatcher() watcher.Path = directory watcher.Filter = dataFile sender = UdpSender(port, group) def onChanged(source, event): print 'Changed:', event.ChangeType, event.FullPath sender.send('DATA:FILE:CHANGED') watcher.Changed += onChanged watcher.EnableRaisingEvents = True while True: Thread.Sleep(1000)
# http://www.ironpython.info/index.php?title=Watching_the_FileSystem from System.IO import FileSystemWatcher from System.Threading import Thread watcher = FileSystemWatcher() watcher.Path = 'c:\\Temp' def onChanged(source, event): print 'Changed:', event.ChangeType, event.FullPath def onRenamed(source, event): print 'Renamed:', event.OldFullPath, event.FullPath watcher.Changed += onChanged watcher.Created += onChanged watcher.Deleted += onChanged watcher.Renamed += onRenamed watcher.EnableRaisingEvents = True # wait for an hour Thread.Sleep(60 * 1000 * 60) """ #HB update code from source file. def getAllTheComponents(onlyGHPython = True): components = []