开发者

execute python script when directory is not empty - Directory Monitoring

开发者 https://www.devze.com 2023-04-12 06:28 出处:网络
I have a python script that converts images and videos withing a directory. The problem, the python script executes manually but I need the script to execute automatically when a file is dropped into

I have a python script that converts images and videos withing a directory. The problem, the python script executes manually but I need the script to execute automatically when a file is dropped into the directory under a linux platform.

What would be the best way to set a python script to watch/monitor a directory?

I've looked into many options but not sure which one j开发者_如何学编程ust simply sets the script to execute when files are dropped into a directory.

Thank in advanced


The 'clean' way to do this is using the inotify system. There is the Pyinotify project if you want to use Python to interface with it.

You don't have to use inotify directly though - there are tools like icrond you can hook into. In fact, the person at that link looks to be trying to do something very similar to what you want - check it out.

Brute force, you could use watch, though that just runs a command periodically, not only when something changes.


Check out PyInotify

Or for an easier example:

PyInotify Tutorial


Use pyinotify:

https://github.com/seb-m/pyinotify

A tutorial is here: https://github.com/seb-m/pyinotify/wiki/Tutorial

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号