Could you please tell me how can I implement the possibility of detecting two files with the same extension in a folder?
That is, I need a folder that will be tracked, and as soon as two files with the extension .txt appear in this folder, then it is necessary to identify the file created earlier than everyone else in the same folder (i.e. it will be the oldest) and display its name on the screen, for example, or any other functions.
I found this method that can track the creation of files in a folder... but unfortunately, the level of my knowledge of Python does not allow me to further develop the idea that I described above.
#!/usr/bin/env python3
import time
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
class EventHandler(FileSystemEventHandler):
def on_created(self, event):
result = (event.event_type, event.src_path)
print(result)
if __name__ == "__main__":
path = r"/root/test/"
event_handler = EventHandler()
observer = Observer()
observer.schedule(event_handler, path, recursive=True)
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()
