python pyinotify 监控文件与目录的变化

简介: !/usr/bin/env pythonencoding:utf-8import osimport sysfrom pyinotify import *class EventHandler(ProcessEvent):def process...

!/usr/bin/env python

encoding:utf-8

import os
import sys
from pyinotify import *

class EventHandler(ProcessEvent):
def process_IN_CREATE(self, event):
print "Create file: %s " % os.path.join(event.path,event.name)
def process_IN_CREATE(self, event):
print "Create file: %s " % os.path.join(event.path,event.name)
def process_IN_MODIFY(self, event):
print "Modify file: %s " % os.path.join(event.path,event.name)
def FSMonitor(path='.'):
wm = WatchManager()
mask = IN_DELETE | IN_CREATE |IN_MODIFY
notifier = Notifier(wm, EventHandler())
wm.add_watch(path, mask,auto_add=True,rec=True)
print 'now starting monitor %s'%(path)
while True:
try:
notifier.process_events()
if notifier.check_events():
print "cccc"
notifier.read_events()
except KeyboardInterrupt:
print "aaaa"
notifier.stop()
break

if name == "main":
FSMonitor(sys.argv[1])

目录
相关文章
|
2天前
|
JSON 安全 数据格式
Python文件操作宝典:一步步教你玩转文件读写
Python文件操作宝典:一步步教你玩转文件读写
|
2天前
|
Python
python搭建文件服务
python搭建文件服务
7 1
|
1天前
|
数据安全/隐私保护 Python
经验大分享:python读取yaml文件
经验大分享:python读取yaml文件
|
2天前
|
Python
揭秘Python安装目录:你的编程宝库隐藏了哪些宝藏?
揭秘Python安装目录:你的编程宝库隐藏了哪些宝藏?
|
2天前
|
存储 Python
Python处理文件的常用代码
Python处理文件的常用代码
|
2天前
|
Python
python文件的读取与写入
python文件的读取与写入
8 0
|
3天前
|
缓存 算法 Python
python文件读写讲解
python文件读写讲解
|
3天前
|
安全 Linux PHP
Python文件读写的详细讲解
Python文件读写的详细讲解
|
13天前
|
存储 Python 内存技术
python WAV音频文件处理—— (1)读写WAV文件
python WAV音频文件处理—— (1)读写WAV文件
43 14
|
1月前
|
数据挖掘 索引 Python
Python 读写 Excel 文件
Python 读写 Excel 文件
120 0

热门文章

最新文章