monitor_dir.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:gpvdm 作者: roderickmackenzie 项目源码 文件源码
def run(self):
        if running_on_linux()==True:
            print("thread: start")
            wm = pyinotify.WatchManager()
            print("wathcing path",self.watch_path)
            ret=wm.add_watch(self.watch_path, pyinotify.IN_CLOSE_WRITE, self.onChange,False,False)
            print(ret)
            print("thread: start notifyer",self.notifier)
            self.notifier = pyinotify.Notifier(wm)
            try:
                while 1:
                    self.notifier.process_events()
                    if self.notifier.check_events():
                        self.notifier.read_events()
            #self.notifier.loop()
            except:
                print("error in notify",sys.exc_info()[0])
        else:
            hDir = win32file.CreateFile (self.watch_path,FILE_LIST_DIRECTORY,win32con.FILE_SHARE_READ | win32con.FILE_SHARE_WRITE | win32con.FILE_SHARE_DELETE,None,win32con.OPEN_EXISTING,win32con.FILE_FLAG_BACKUP_SEMANTICS,None)

            while 1:
                results = win32file.ReadDirectoryChangesW (hDir,1024,True,
                win32con.FILE_NOTIFY_CHANGE_FILE_NAME |
                win32con.FILE_NOTIFY_CHANGE_DIR_NAME |
                win32con.FILE_NOTIFY_CHANGE_ATTRIBUTES |
                win32con.FILE_NOTIFY_CHANGE_SIZE |
                win32con.FILE_NOTIFY_CHANGE_LAST_WRITE |
                win32con.FILE_NOTIFY_CHANGE_SECURITY,
                None,
                None)

                for action, file in results:
                    full_filename = os.path.join (self.watch_path, file)
                    self.onChange(full_filename)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号