一种“听"音乐的方式.在Linux上从Python更改文件系统? [英] A way to "listen" for changes to a file system from Python on Linux?

查看:66
本文介绍了一种“听"音乐的方式.在Linux上从Python更改文件系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够检测到在给定的目录树(或树集)中创建新文件或修改或删除现有文件的时间.这样做的蛮力方法是重新扫描树以查找更改,但是我正在寻找一种更中断驱动"的解决方案,其中文件系统告诉我代码更改时发生了什么更改,而不是我的代码必须通过连续扫描成千上万的文件以查找更改来进行轮询".

I want to be able to detect whenever new files are created or existing files are modified or deleted within a given directory tree (or set of trees). The brute force way to do this would be to just rescan the tree looking for changes, but I'm looking for a more "interrupt driven" solution where the file system tells my code what changed when it changes, rather than my code having to "poll" by continuously scanning through thousands of files looking for changes.

首选在Python中执行此操作的方法,但是如果我必须用C编写本机模块,则万不得已.

A way to do this in Python is preferred, but if I have to write a native module in C that's ok as a last resort.

推荐答案

pyinotify 是恕我直言无需扫描目录即可获取系统更改的唯一方法.

pyinotify is IMHO the only way to get system changes without scanning the directory.

这篇关于一种“听"音乐的方式.在Linux上从Python更改文件系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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