Reputation: 133
I have a specific folder in which I download certain .zip files. I am writing a python script to automate the unzip, upload, and deletion of files from this folder. Is there a way to automatically trigger my python script each time a zip file is downloaded to this folder?
[EDIT] : i am on osx mavericks, sorry for not mentioning this from the start
Upvotes: 2
Views: 1398
Reputation: 133
Since I am on Mac OSX Mavericks, my best bet is to use watchdog - the most popular python module for this kind of stuff.
Upvotes: 0
Reputation: 830
The easiest way I can think of: Make a cronjob lets say every 1 minute, that launches a script to check the directory in question for any new zip files. If found it will trigger unziping, upload and deletion.
if you don't want to create a cronjob you can always think about creating a daemon (but why bother)
Upvotes: 1
Reputation: 318638
Yes, you can use inotify (e.g. using pyinotify) to get a callback whenever a new file is created. It is not available on Windows though. There might be a similar api available, but I don't know if there are python bindings for that API.
Upvotes: 2