Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accounting for lower and uppercase in glob

Tags:

python

I need to pass an extension to function, and then have that function pull all files with that extension in both lower and uppercase form.

For example, if I passed mov, I need to function to do:

videos = [file for file in glob.glob(os.path.join(dir, '*.[mM][oO][vV]'))] 

How would I accomplish the lower + upper combination above given a lowercase input?

like image 357
David542 Avatar asked Nov 15 '25 12:11

David542


1 Answers

Something like this?

>>> def foo(extension):
...     return '*.' + ''.join('[%s%s]' % (e.lower(), e.upper()) for e in extension)
... 
>>> foo('mov')
'*.[mM][oO][vV]'
like image 133
Nolen Royalty Avatar answered Nov 18 '25 05:11

Nolen Royalty



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!