I think what you are looking for is a folder monitor which performs actions based on the event handling in the folder. I recommend using the 'watchdog' library in python to monitor the folder for incoming or outgoing files while the 'subprocess' library executes actions like reading and deleting. Refer to the code below
Code:
import subprocess
import time
import os
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
def on_created(event):
print("A File is arrived",os.path.basename(event.src_path))
time.sleep(10)
os.remove(event.src_path)
def on_deleted(event):
print("File Deleted")
if __name__ == "__main__":
event_handler= FileSystemEventHandler()
event_handler.on_created=on_created
event_handler.on_deleted=on_deleted
path="A:/foldername" #"Enter the folder path" you want to monitor here
observer= Observer()
observer.schedule(event_handler,path,recursive=False) #If recursive is set to be True it will check in the subdirectories for contents if a folder is added to our path
observer.start()
try:
while True:
time.sleep(15) # Sleeps for 15 seconds
except KeyboardInterrupt:
observer.stop() # The code terminates if we hit any key in the folder or else it keeps running for ever
observer.join()
Also, if you want to read the file before deleting then add the file reading code in the on_created method before "os.remove" and the code should work fine for you now!