If you look into fnmatch source code closely, it internally converts the pattern to a regular expression, mapping *
into .*
(and not [^/]*
or similar) and thus does not care anything for directory separators /
- unlike UNIX shells:
while i < n:
c = pat[i]
i = i+1
if c == '*':
res = res + '.*'
elif c == '?':
res = res + '.'
elif c == '[':
...
Thus
>>> fnmatch.fnmatch('a/b/d/c', 'a/*/c')
True
>>> fnmatch.fnmatch('a/b/d/c', 'a/*************c')
True