r1chardj0n3s / parse

Parse strings using a specification based on the Python format() syntax.
http://pypi.python.org/pypi/parse
MIT License
1.72k stars 101 forks source link

Find all files with matching paths #135

Closed martinResearch closed 1 year ago

martinResearch commented 3 years ago

Thank you for this very useful library. I would like very much to have a function in the parse module to find all files in a folder and its subfolders whose relative path to the root folder matches a specified fstring format pattern. Similarly to the glob.glob function it would walk through the file system to find matching files but would use parse instead of fnmatch. It would preferably avoid listing all files in the root folder subfolders, similarly to glob. It would be a great alternative to glob. Would it make sense to add this functionality to the parse module, or is out of its scope?

mathause commented 2 years ago

Take a look at https://github.com/mathause/filefinder - however, I am not sure it matches your specs & under the hood it also uses glob but it also parses the patterns such that you get the metadata back.

It could however be possible to write a custom function to walk the filesystem and use parse to find the paths matching the pattern.

wimglenn commented 1 year ago

Yeah, this is out of scope. parse currently is totally agnostic about any filesystem, it just works with strings.

For a glob replacement which uses parse instead of wildmatch, recommend to just put together some for-loop with os.walk + parse.