开发者

How to monitor a directory for changes in Python? [duplicate]

开发者 https://www.devze.com 2023-04-08 02:43 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Monitoring files/directories with python
This question already has answers here: Closed 11 years ago.

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.

0

精彩评论

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