I currently have 2 ways of looking at a folder and checking to see if there is a new file in it. I have used watchdog and os. Below are the code snippets of what I have used.
Watchdog:
import sys
import time
import logging
from watchdog.observers import Observer
from watchdog.events import LoggingEventHandler
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO,
format='%(asctime)s - %(message)s',
datefmt='%Y-%m-%d - %H:%M:%S')
path2 = 'G:\\Actuarial\\Pricing\\IBOTT\\Team\\NP\\Projects\\Claims Automation\\Processed Files'
event_handler = LoggingEventHandler()
observer = Observer()
observer.schedule(event_handler, path2, recursive=True)
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()
OS:
for filename in os.listdir('Processed Files'):
if filename == None or filename == '.ipynb_checkpoints':
pass
else:
print('File: ' + str(filename))
I'm trying to implement a program that is able to take the excel file that has been input into a folder, if that be in a zip format or a normal excel format and process it and then move it.
Watchdog is able to display any new files that are being moved into the folder, however, I'm not sure how I can use this to actually process the file? Is there a way to get the path or the file that the observer sees and read that instead?