How to monitor a directory for changes in Python? [duplicate]
Possible Duplicate:
Monitoring files/directories with python
I am making an API server that allows hot-deploying of code. And yes, there are dozens of questions about re-importing modules. I just want to monitor a directory, and when a change is detected, perform an action.
path_to_monitor="c:\\app\\package"
def action():
do_something()
dm=dir_monitor(path_to_mo开发者_JAVA技巧nitor,action)
dm.start()
I need a solution that is mature and cross-platform.
You can use a Python thread which uses os.listdir()
to list files. If you want to monitor other file properties than the file name, os.stat
might help you.
精彩评论