| 9 | watched = collections.defaultdict(lambda: -1.0) |
| 10 | |
| 11 | def walk(): |
| 12 | walked = [] |
| 13 | for folder in folders: |
| 14 | for current, _, files in os.walk(folder): |
| 15 | for f in files: |
| 16 | if pattern and not pattern.search(f): |
| 17 | continue |
| 18 | path = os.path.join(current, f) |
| 19 | |
| 20 | info = os.stat(path) |
| 21 | new_time = info.st_mtime |
| 22 | |
| 23 | if new_time > watched[path] > 0: |
| 24 | on_change(path, new_time, False) |
| 25 | |
| 26 | watched[path] = new_time |
| 27 | walked.append(path) |
| 28 | |
| 29 | # Look for deleted files |
| 30 | for w in [x for x in watched.keys() if x not in walked]: |
| 31 | del watched[w] |
| 32 | on_change(w, -1, True) |
| 33 | |
| 34 | while True: |
| 35 | walk() |