Checking if a list of files exists before proceeding?

Viewed 7657

I have some pandas code running for 9 different files each day. Currently, I have a scheduled task to run the code at a certain time but sometimes the files have not been uploaded to the SFTP by our client on time which means that the code will fail. I want to create a file checking script.

3 Answers

Another much simpler approach using map:

import os

file_names_list = ['file1', 'file2', 'file3']

if all(list(map(os.path.isfile,file_names_list))):
   # do something
else:
   # do something else!
Related