我正在使用此代碼來檢測文件夾中創建文件/目錄的時間。當在指定文件夾中創建新文件/目錄時,它工作正常。但它不會在將移動到文件夾中時通知或記錄文件/目錄。我如何檢測?python pyinotify已移動文件
#!/usr/bin/env python
# monitors both files and dirs
import os
import pyinotify
from datetime import datetime
timestamp = datetime.today()
wm = pyinotify.WatchManager()
mask = pyinotify.IN_CREATE
class PTmp(pyinotify.ProcessEvent):
def process_IN_CREATE(self, event):
print "Created: %s " % os.path.join(event.path, event.name)
event_log = open('/home/saad/Code/test/event_log', 'a')
event_log.write(event.name + ' - ' + timestamp.strftime('%c') + '\n')
event_log.close()
notifier = pyinotify.Notifier(wm, PTmp())
wdd = wm.add_watch('/home/saad/Code/test/foo', mask, rec=True)
while True:
try:
notifier.process_events()
if notifier.check_events():
notifier.read_events()
except KeyboardInterrupt:
notifier.stop()
break
作品。非常感謝! – koogee 2013-04-09 17:09:43