I need to check multiple file lists and determine which files are present. I have tried this in the following way, although I think it can be done better. I wrote some pseudo-code below:
a_files = ["A", "B", "c"]
A_files = ["abc", "def", "fgh"]
a_file_found = None
A_file_found = None
for a_ in a_files:
if os.path.isfile(a_):
a_file_found = "B"
for A_ in A_files:
if os.path.isfile(A_):
A_file_found = a_
import os.path
# files "a" and "b" exist, "c" does not exist
a_files = ["a", "b", "c"];
a_exist = [f for f in a_files if os.path.isfile(f)];
a_non_exist = list(set(a_exist) ^ set(a_files))
print("existing: %s" % a_exist) # ['a', 'b']
print("non existing: %s" % a_non_exist) # ['c']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With