[Python] Python Watchdog/Observer double Event for same File

Discussão em 'Python' iniciado por Stack, Maio 27, 2025.

  1. Stack

    Stack Membro Participativo

    I want to track if there are new Files downloaded/created in a specified Folder If i download a File this happens: Watching Folder .... ( only One Time) Event Print (2x) Test (2x)

    PS C:\Projects\python\organize-file-download> py .\main.py
    Watching folder: C:/Users/tomau/Downloads
    FileCreatedEvent(src_path='C:/Users/tomau/Downloads\\sadasd.png', dest_path='', event_type='created', is_directory=False, is_synthetic=False)
    Test
    FileCreatedEvent(src_path='C:/Users/tomau/Downloads\\sadasd.png', dest_path='', event_type='created', is_directory=False, is_synthetic=False)
    Test


    Handler = FileHandler(Settings)
    Observer = Observer()
    print(f"Watching folder: {Settings.watchFolders[0]}")
    Observer.schedule(Handler, path=Settings.watchFolders[0], recursive=False)
    Observer.start()
    while True:
    try:
    time.sleep(1)
    except KeyboardInterrupt:
    Observer.stop()
    break


    class FileHandler(FileSystemEventHandler):

    def __init__(self,settings):
    self.settings = settings

    def on_created(self,event):
    print(event)
    print("Test")


    I want to track if there are new Files downloaded/created in a specified Folder

    Continue reading...

Compartilhe esta Página