so i have a os.walk code
search = self.search.get_text()
top = '/home/bludiescript/tv-shows'
for dirpath, dirnames, filenames in os.walk(top):
for filename in filenames:
if fnmatch.fnmatch(filename, search)
print os.path.join([dirpath, filename])
on python docs it shows you can match any seq of chars with [seq] pattern but no matter how i try to implement that it give so kind of error or no results at all.
so what would be the correct implementation to match the seq of cars in search so it will print out the file or files that match
implementations i tried
if fnmatch.fnmatch(filename, [search]) error i got was typeerror unhasable type : 'list'
if fnmatch.fnmatch[filename, search] error i got was typeerror fnmatch function is not subscriptable
if fnmatch.fnmatch([filename, search]) error typeerror fnmatch takes two arguments 1 given
if fnmatch.fnmatch([filename], search) error typeerror expected string or buffer
if fnmatch.fnmatch([search], filename) error typeerror expected string or buffer
if fnmatch.fnmatch(filename, search, [seq]) error nameerror global name seq not defined
if fnmatch.fnmatch(filename, '[search]')
no errors but did not produce any results
search values
hello, mkv, merry 1, 2, 3, 4, 5, 6, 7, etc...
fnmatch implements the Unix shell wildcard syntax. So whatever you can type in an ls
command (for example) will work:
>>> fnmatch.fnmatch("qxx", "[a-z]xx")
True
>>> fnmatch.fnmatch("abc", "a??")
True
>>> fnmatch.fnmatch("abcdef", "a*f")
True
>>> fnmatch.fnmatch("abcdef", "a*[f-k]")
True
Keep in mind, fnmatch is purely a string matching operation. If you find it more convenient to use a different pattern style, for example, regexes, then simply use regex operations to match your filenames.
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