[Python-ideas] find-like functionality in pathlib

Erik python at lucidity.plus.com
Fri Dec 4 16:16:35 EST 2015


On 04/12/15 19:08, Ram Rachum wrote:
> 2. Not sure how I would use fnmatch, because I wouldn't want to give it
> the list of all files recursively, since that would be a long list of
> files (lots of files in ".git" folder that I want to ignore.) I want it
> to first ignore everything in the ".git" folder completely without going
> over all the files, and then include all the other files recursively.

Ram - os.walk() is probably the closest existing thing to what you want 
here (if it's called with topdown=True - the default - then you can 
remove the ".git" entry from the list of directories to prevent the 
walker from descending into that directory completely).

I know: this is still stepping out of pathlib. However, it's probably 
what you want if you want to get something working soon ;)

FWIW, this is not unrelated to my recent request for an os.walk() which 
returns the DirEntry objects - a thread that I am in the process of 
trying to summarise so that it doesn't drop off the RADAR (though it 
seems like this whole area is a can of worms ...).

E



More information about the Python-ideas mailing list