监视目录中的文件更改 [英] Watching for file changes within a directory

查看:114
本文介绍了监视目录中的文件更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:


我试图编写一个应用程序,它必须在特定目录及其子目录中修改或添加文件时执行操作。

I am trying to write an application which must perform an action when files are modified or added within a particular directory and its sub-directories.

我想象理想的解决方案是绑定到操作系统在修改文件或目录时触发的某种类型的系统事件。另一个不太理想的解决方案是我的应用程序手动递归地检查目录中的文件更改是否在指定的时间间隔,但是如果每隔几分钟必须检查大量文件, 。

I imagine that an ideal solution would be to bind to some type of system event that is fired by the operating system when a file or directory is modified. Another less-than-ideal solution would be for my application to manually, recursively check for file changes within a directory at a specified time interval, but this could get incredibly process-intensive if there are lots of files that must be checked every few minutes.

摘要:

Summary: What is the best way for my application to watch for file changes within a directory?

对于这个问题的范围,假设我的应用程序是用Python编写的,操作系统是基于Linux的,但是为其他语言和操作系统(如Windows或Mac OS)解决这个问题的一般化答案是最受欢迎的。

For the scope of this question, assume that my application is written in Python and the operating system is Linux-based, but generalized answers that solve this problem for other languages and operating systems such as Windows or Mac OS are most welcome.

推荐答案

我认为libnotify是你正在寻找的。几乎所有的语言和操作系统都可以找到它。这里是 Python / Linux

I think libnotify is what you're looking for. You'll find it available for pretty much every language and OS. Here it is for Python/Linux

这篇关于监视目录中的文件更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆