9

我需要监视(使用watchdog)单个文件,而不是整个目录。

避免监视整个目录的最佳方法是什么?我想

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

可能会有所帮助,但是如何为我的文件( C:/dir1/dir2/file.txt)定义适当的模式?

4

2 回答 2

4

如果您想观看类似的文件路径C:/dict1/dict2/file.txt,我认为这就是您的模式。里面没有通配符,所以它应该可以按原样使用。

顺便说一句,如果 Watchdog 给您带来麻烦,您也可以考虑使用 Pinotify:https ://github.com/seb-m/pyinotify

于 2013-04-28T09:34:06.107 回答
2

提供模式的方法PatternMatchingEventHandler

 from watchdog.events import PatternMatchingEventHandler

 class MyHandler(PatternMatchingEventHandler):
     patterns = ["*.xml", "*.log", "*/test.txt"] # */test.txt to watch that specifi file
于 2016-02-08T13:32:40.180 回答