[Tutor] Monitor directory Python3 script
Nathan D'Elboux
nathan.delboux at gmail.com
Tue Nov 12 17:58:47 EST 2019
Hi all,
Im a student learning Python3. i have a small script id like to make
that would monitor some subdirectories for any new files that are
placed in there and move them to another directory on the same
partition
Im looking around for modules to use and came across shutil. This
seems ok at first but seems more for batch processing so copy files
from dir1 to dir2 every time cron runs which could lead to the same
file being copied. Im thinking if i used pyinotify to monitor the
directory then only newly added files would be copied and not
everything before it every time it copies.
So if i had a dir structure like this
/Mountpoint/directory1/
/2019-01-10
/2019-01-11
/Mountpoint/directory2
/2019-01-10
/2019-01-11
/Mountpoint/destination/directoryX/
So i have new files being dropped into the current date directory each
day until end of day, i just want to monitor the current date each day
and copy anything that comes into it over to the
/destination/directoryX/ dir as a big bucket. Then i can process them
further once they have reached their destination
Is Pyinotify the best module for this within Python3 ecosystem? This
will be on a linux system, i have started on writing some of the code
based on this article
https://www.linode.com/docs/development/monitor-filesystem-events-with-pyinotify/
just after feedback as if this concept is the right approach or if
theres a better easier way to do it i may be ignoring.
Thanks
Nathan
More information about the Tutor
mailing list