Non recursively
In order to retrieve the files (and files only) of a directory "path", with "globexpression":
list_path = [i for i in os.listdir(path) if os.path.isfile(os.path.join(path, i))]
result = [os.path.join(path, j) for j in list_path if re.match(fnmatch.translate(globexpression), j, re.IGNORECASE)]
Recursively
with walk:
result = []
for root, dirs, files in os.walk(path, topdown=True):
result += [os.path.join(root, j) for j in files \
if re.match(fnmatch.translate(globexpression), j, re.IGNORECASE)]
Better also compile the regular expression, so instead of
re.match(fnmatch.translate(globexpression)
do (before the loop):
reg_expr = re.compile(fnmatch.translate(globexpression), re.IGNORECASE)
and then replace in the loop:
result += [os.path.join(root, j) for j in files if re.match(reg_expr, j)]