<div dir="auto">I like the idea. I think an argument to os.walk() is the simplest option for most users. But per some comments, "hidden" is actually more subtle than the filesystem bit sometimes. I.e. dot-files, ~ suffix, maybe .bak, etc.<div dir="auto"><br></div><div dir="auto">I'd suggest meeting the ideas slightly and making the new argument 'filter' or 'skip' that takes a callable. Default to None, but provide an os.is_hidden that users don't need to figure out how to implement. E.g.</div><div dir="auto"><br></div><div dir="auto">os.walk(PATH, skip=os.is_hidden)</div><div dir="auto"><br></div><div dir="auto">os.walk(PATH, skip=lambda entry: entry.name.endswith(('~', '.bak', '.tmp')))</div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, May 8, 2018, 5:47 AM Oleg Broytman <<a href="mailto:phd@phdru.name">phd@phdru.name</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi!<br>
<br>
On Tue, May 08, 2018 at 07:12:35AM +0000, Yuval Greenfield <<a href="mailto:ubershmekel@gmail.com" target="_blank" rel="noreferrer">ubershmekel@gmail.com</a>> wrote:<br>
> If you<br>
> want to avoid duplicate `stat` calls, you'll probably write:<br>
> <br>
> import os<br>
> import stat<br>
> def is_hidden(st):<br>
>     return bool(st.st_file_attributes & stat.FILE_ATTRIBUTE_HIDDEN)<br>
> def visible_walk(path):<br>
>     for entry in os.scandir(path):<br>
>         if entry.is_dir():<br>
>             if not is_hidden(entry.stat()):<br>
>                 yield from visible_walk(entry.path)<br>
>         else:<br>
>             if not is_hidden(entry.stat()):<br>
>                 yield entry.path<br>
<br>
   So anyone who wants to filter os.walk() must reimplement os.walk()<br>
themselves instead of passing something like filter_dir and filter_file<br>
(or accept_dir/accept_file) to os.walk()? Kind of painful, no?<br>
<br>
> Cheers,<br>
> Yuval<br>
<br>
Oleg.<br>
-- <br>
     Oleg Broytman            <a href="http://phdru.name/" rel="noreferrer noreferrer" target="_blank">http://phdru.name/</a>            <a href="mailto:phd@phdru.name" target="_blank" rel="noreferrer">phd@phdru.name</a><br>
           Programmers don't die, they just GOSUB without RETURN.<br>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank" rel="noreferrer">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer noreferrer" target="_blank">http://python.org/psf/codeofconduct/</a><br>
</blockquote></div>