Python Get File Regardless Of Upper Or Lower
I'm trying to use this on my program to get an mp3 file regardless of case, and I've this code: import glob import fnmatch, re def custom_song(name): for song in re.compile(fn
Solution 1:
fnmatch.translate
expects a string as an argument, not a list/iterator of filenames as would be returned by glob, thus something like:
pattern= re.compile(fnmatch.translate(name + "*.mp3"),
re.IGNORECASE)
Also, you must iterate over some filenames and see if they match
the compiled pattern:
directory = '../music/'for name inos.listdir(directory):
if pattern.match(name):
print(os.path.join(directory, name))
Post a Comment for "Python Get File Regardless Of Upper Or Lower"