Python Monitor Directories and Subdirectories for file additions/changes
I have created this code to retrieve list paths of all the files within a
certain directory and its subdirectories:
our_dir='c:\\mydocs'
walk=os.walk(our_dir)
for path, folders, files in walk:
for f in files:
file_path=os.path.join(path,f)
print file_path
Or to write these paths into a text file.
How can I run the program on a daily basis and retrieve only the paths of
the files added or changed? I think I can use os to check every file for
the last modified, but this would be too ineffecient for 300K+ files and
hundreds of subfolders.
Any neat way of doing this? I am aware of the other answers:
Monitoring files/directories with python
How do I watch a file for changes using Python?
and of watchdong, https://pypi.python.org/pypi/watchdog
But this doesn't seem to do the exact thing that I want, because the
directory is so huge so polling and file comparison wouldn't work, and the
computer from which I run the monitoring can be turned off and so the
monitoring will be interrupted.
In a nut shell, I need:
A text file for the file paths for the first run
A new text file generated daily for the files changed since the previous run
I am using windows.
No comments:
Post a Comment