[Tutor] Invoking python script

Oscar Benjamin oscar.j.benjamin at gmail.com
Mon Feb 18 00:27:33 CET 2013

On 17 February 2013 15:57, Alan Gauld <alan.gauld at btinternet.com> wrote:
> On 17/02/13 09:14, Brajesh pant wrote:
>> Actually i want to  build a utility such that a when a file or folder
>> is copied i want to automatically run my python script ..
> And this is a far different thing because you specifically want to monitor
> the file-system regardless of how the files get moved.
> This is very dependent on the OS and even the file-system. For example with
> a journalling file-system it will be much easier to do this than with the
> old DOS FAT based system or even older Unix systems like ext2.
> And I don;t know of any Python modules that would help directly, I suspect
> you need to get down 'n dirty with the OS itself.
> I'll be interested to see what other folks suggest on this one.

I would suggest watchdog:
There are other packages that do this but watchdog is the only one
that I have used.

This is a Python package that enables you to watch for changes in a
directory. I've used it on Linux but it claims to work on Windows, OSX
and BSD as well. Using this you can run any Python code you like when
a change occurs.

The way it works is that you have a script that imports and uses the
watchdog module. You run that script telling it to watch a particular
folder and while it is running it will be notified of any changes and
will run the code that you specify for each event.


More information about the Tutor mailing list