sbmsr
sbmsr

Reputation: 133

trigger python script everytime a file is downloaded into a specific folder

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

Answers (3)

sbmsr
sbmsr

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

Wissam Youssef
Wissam Youssef

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

ThiefMaster
ThiefMaster

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

Related Questions