MCPcopy Create free account
hub / github.com/ActiveState/code / f

Function f

recipes/Python/215418_Watching_directory_tree/recipe-215418.py:23–50  ·  view source on GitHub ↗
(unused, dirname, files)

Source from the content-addressed store, hash-verified

21
22 all_files = {}
23 def f (unused, dirname, files):
24 # Traversal function for directories
25 for filename in files:
26 path = os.path.join(dirname, filename)
27
28 try:
29 t = os.stat(path)
30 except os.error:
31 # If a file has been deleted between os.path.walk()
32 # scanning the directory and now, we'll get an
33 # os.error here. Just ignore it -- we'll report
34 # the deletion on the next pass through the main loop.
35 continue
36
37 mtime = remaining_files.get(path)
38 if mtime is not None:
39 # Record this file as having been seen
40 del remaining_files[path]
41 # File's mtime has been changed since we last looked at it.
42 if t.st_mtime > mtime:
43 changed_list.append(path)
44 else:
45 # No recorded modification time, so it must be
46 # a brand new file.
47 changed_list.append(path)
48
49 # Record current mtime of file.
50 all_files[path] = t.st_mtime
51
52 # Main loop
53 rescan = False

Callers

nothing calls this directly

Calls 3

joinMethod · 0.45
getMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected