Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On_moved not able to detect moved file/folder on certain path. #1023

Open
racharya123 opened this issue Jan 10, 2024 · 0 comments
Open

On_moved not able to detect moved file/folder on certain path. #1023

racharya123 opened this issue Jan 10, 2024 · 0 comments

Comments

@racharya123
Copy link

racharya123 commented Jan 10, 2024

i am working on a watchdog which will print a statement each time a file is moved to the watched path.

from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler


class MyHandler(FileSystemEventHandler):
    def on_moved(self, event):
        print("on_moved called")
        if event.is_directory:
            print(f"Directory moved: {event.src_path} to {event.dest_path}")
        else:
            print(f"File moved: {event.src_path} to {event.dest_path}")


def watch_location(path):
    event_handler = MyHandler()

    observer = Observer()
    observer.schedule(event_handler, path, recursive=True)
    observer.start()
    print("observer setup")
    try:
        while True:
            pass
    except KeyboardInterrupt:
        observer.stop()

    observer.join()


watch_location("/Users/xyz/workspace/new-test")

when i am setting it for path "/Users/xyz/workspace/" its working fine but when i use path "/Users/xyz/workspace/new-test" it stops working and even the on_moved function isn't called.

here are permissions of the folders
drwxr-xr-x 130 xyz staff 4160 Jan 10 13:20 workspace
drwxr-xr-x 11 xyz staff 352 Jan 10 15:35 emulator_new

can anyone help me with this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant