Is there a simpler way to do the following to iterate over xls
files regardless of capitalization?
for file in [glob.glob(os.path.join(dir, '*.xls')), glob.glob(os.path.join(dir, '*.XLS'))]:
glob and the underlying fnmatch have no flag for case-independence, but you can use brackets:
for file in glob.iglob(os.path.join(dir, '*.[xX][lL][sS]')):
You could do the matching "manually" without glob
:
for file in os.listdir(dir):
if not file.lower().endswith('.xls'):
continue
...
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