Python automation- move file automatically into another folder- code not carrying through

263 Views Asked by At

I created a text file and want to move it from one folder to another here. Everytime i run it in idle and try it nothing happens

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

import os
import json
import time

class MyHandler(FileSystemEventHandler):
    def on_modified(self, event):
        for filename in os.listdir(folder_to_track):
            src = folder_to_track + "/" + filename
            new_destination = folder_destination + "/" + filename
            os.rename(src, new_destination)

folder_to_track = "/Users/nimit/Desktop/New"
folder_destination = "/Users/nimit/Desktop/New2"
event_handler = MyHandler()
observer = Observer()
observer.schedule(event_handler, folder_to_track, recursive=True)

try:
    while True:
        time.sleep(10)
except KeyboardInterrupt:
    observer.stop()
observer.join()
0

There are 0 best solutions below