I am having an issue where I have a Power Automate (Cloud) flow that automatically saves e-mail attachments in a specific folder and a Python Watchdog script watching that folder. However, the script does not trigger when files are added from the flow, only if I add them manually. Everything otherwise working.
I have tried it with both on_creation
and on_any_event
conditions but it does not seem to work.
I wanted the script to trigger automatically when the files were added using PA.
import os
import time
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
import subprocess
class NewFileHandler(FileSystemEventHandler):
def on_any_event(self, event):
if event.is_directory:
return
# Replace with the path to your script
script_path = r"path"
subprocess.run(["python", script_path])
if __name__ == "__main__":
folder_to_watch = r"path"
event_handler = NewFileHandler()
observer = Observer()
observer.schedule(event_handler, path=folder_to_watch, recursive=True)
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()