Monitoring a single file

和自甴很熟 提交于 2019-12-07 02:05:19

问题


I need to monitor (using watchdog) a single file, not a whole directory.

What is the best way to avoid monitoring a whole directory? I suppose this

class watchdog.events.PatternMatchingEventHandler(patterns=None, ignore_patterns=None, ignore_directories=False, case_sensitive=False)[source]

could be helpful, but how to define an appropriate pattern for my file (C:/dir1/dir2/file.txt)?


回答1:


If you want to watch a file path like C:/dict1/dict2/file.txt, I think that's your pattern right there. There are no wildcards in, so it should be usable as-is.

As an aside, if Watchdog is giving you trouble, you could also consider Pyinotify: https://github.com/seb-m/pyinotify




回答2:


The way to provide patterns for PatternMatchingEventHandler is

 from watchdog.events import PatternMatchingEventHandler

 class MyHandler(PatternMatchingEventHandler):
     patterns = ["*.xml", "*.log", "*/test.txt"] # */test.txt to watch that specifi file


来源:https://stackoverflow.com/questions/16261425/monitoring-a-single-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!