我正在使用此代码来检测何时在文件夹中创建文件/目录。在指定文件夹中创建新文件/目录时,它可以正常工作。但是当它们被移动到文件夹中时,它不会通知或记录文件/目录。我怎样才能检测到呢?
#!/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