Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. #coding:utf8
  2. #author:lcamry
  3.  
  4. from watchdog.observers import Observer
  5. from watchdog.events import *
  6. import time
  7.  
  8. class FileEventHandler(FileSystemEventHandler):
  9. def __init__(self):
  10. FileSystemEventHandler.__init__(self)
  11.  
  12. def on_moved(self, event):
  13. if event.is_directory:
  14. print("directory moved from {0} to {1}".format(event.src_path,event.dest_path))
  15. else:
  16. print("file moved from {0} to {1}".format(event.src_path,event.dest_path))
  17.  
  18. def on_created(self, event):
  19. if event.is_directory:
  20. print("directory created:{0}".format(event.src_path))
  21. else:
  22. print("file created:{0}".format(event.src_path))
  23.  
  24. def on_deleted(self, event):
  25. if event.is_directory:
  26. print("directory deleted:{0}".format(event.src_path))
  27. else:
  28. print("file deleted:{0}".format(event.src_path))
  29.  
  30. def on_modified(self, event):
  31. if event.is_directory:
  32. print("directory modified:{0}".format(event.src_path))
  33. else:
  34. print("file modified:{0}".format(event.src_path))
  35.  
  36. if __name__ == "__main__":
  37. observer = Observer()
  38. event_handler = FileEventHandler()
  39. observer.schedule(event_handler,"/home/cmput274/database",True)
  40. observer.start()
  41. try:
  42. while True:
  43. time.sleep(1)
  44. except KeyboardInterrupt:
  45. observer.stop()
  46. observer.join()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement