I am coding a dropbox like software in python. I am using watchdog
to monitor the file system:
class MyHandler(FileSystemEventHandler):
def on_created(self, event):
create_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
print create_time, event.event_type, event.src_path
def on_deleted(self, event):
delete_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
print delete_time, event.event_type, event.src_path
def on_modified(self, event):
modify_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
print modify_time, event.event_type, event.src_path
def on_moved(self, event):
move_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
print move_time, "moved from", event.src_path, "to", event.dest_path
This code works fine (all kinds of events) on my Mac but fails to detect delete event in ubuntu. However, if I do a rm
instead of dragging the file to trash, it works fine (watchdog
reports the event).
Is there something wrong here? How shall I fix it?
Thank you very much!
It's because when you "dragging the file to trash" or click "delete" in file mangers, you are really just moving the file to the .Trash folder, not deleting it. There are some difficulties with detecting these kind of moves being discussed here: https://github.com/gorakhargosh/watchdog/issues/46