Closed yedpodtrzitko closed 1 year ago
@yedpodtrzitko Sounds like you want to use globmatch
instead of fnmatch
. fnmatch
does file name matching, not path matching. globmatch
matches file glob paths.
For example:
>>> from wcmatch import glob
>>> glob.globmatch('a/b/c/z.txt', 'a/**/z.txt', flags=glob.GLOBSTAR)
True
Thanks for your comment. Unfortunately I dont work directly with a filesystem, but with a list of paths returned from API representing filesystem. And I need to filter this list using the glob-like patterns, but since it's not filesystem the only tool I can use is fnmatch
.
Please read the section I linked. The documentation states:
By default, globmatch and globfilter do not operate on the file system. This is to allow you to process paths from any source, even paths that are not on your current system.
You can configure it to use Windows or Unix patch logic, depending on what you need.
For clarification, if fnmatch
were to use PATHNAME
, it would operate exactly like globmatch
, so what you want is globmatch
.
Ah ok, that does the trick. Thanks
Hi, I'd like to have
fnmatch
behaving similar way asglob()
/wcmatch()
, where*
would match only one level of directories:this would work as expected:
however the flag
PATHNAME
is not allowed infnmatch()
, and it gets stripped via_flag_transform()
.Would you accept PR exposing the flag there? Or is there any way how to achieve this behaviour currently? Thanks.