user2125827 user2125827 - 1 month ago 5
Python Question

pattern match failing while finding a file

I am trying to find a file

*tech.so
in a given path as below but somehow the
fnmatch.fnmatch(name, pattern)
is failing,can anyone suggest how to fix this?

import os, fnmatch

path = "\\\\location1\\build1\\obj\\vendor\\qcom\\opensource\\tech"

def find(pattern, path):
result = []
for root, dirs, files in os.walk(path):
for name in files:
#print name
if fnmatch.fnmatch(name, pattern):
result.append(os.path.join(root, name))
return result

result = find('*.tech.so', path)
print result//prints empty string

cco cco
Answer

Your match pattern is *.tech.so, but the name you're looking for is caq_cdl3_tech.so

fnmatch patterns aren't the same as a regex, so . only matches a literal ., not 'any single character' as it would in a regex.

using *tech.so or *_tech.so as the pattern should work.