Re: [Python-ideas] Please consider skipping hidden directories in os.walk, os.fwalk, etc.

2018-05-09 Thread Nathaniel Smith
There are hidden directories, and then there are hidden directories :-). It makes sense to me to add an option to the stdlib functions to skip directories (and files) that the system considers hidden, so I guess that means dotfiles on Unix and files with the hidden attribute on Windows. But if you

Re: [Python-ideas] Please consider skipping hidden directories in os.walk, os.fwalk, etc.

2018-05-09 Thread Wes Turner
fnmatch.filter does Unix filename pattern matching. https://docs.python.org/3/library/fnmatch.html#fnmatch.filter grin and grind are like grep and find with options to filter hidden files and VCS directories by default. https://pypi.org/project/grin/ There's an example of using the Python API her

Re: [Python-ideas] Please consider skipping hidden directories in os.walk, os.fwalk, etc.

2018-05-09 Thread Steve Barnes
On 08/05/2018 15:53, Giampaolo Rodola' wrote: > > > On Tue, May 8, 2018 at 2:00 PM, David Mertz > wrote: > > 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

Re: [Python-ideas] Please consider skipping hidden directories in os.walk, os.fwalk, etc.

2018-05-08 Thread Random832
On Mon, May 7, 2018, at 02:05, Steve Barnes wrote: > In a lot of uses of os.walk it is desirable to skip version control > directories, (which are usually hidden directories), to the point that > almost all of the examples given look like: CVS isn't a hidden directory on Linux. Maybe it can be o

Re: [Python-ideas] Please consider skipping hidden directories in os.walk, os.fwalk, etc.

2018-05-08 Thread Giampaolo Rodola'
On Tue, May 8, 2018 at 2:00 PM, David Mertz wrote: > 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. > > I'd suggest

Re: [Python-ideas] Please consider skipping hidden directories in os.walk, os.fwalk, etc.

2018-05-08 Thread Eric Fahlgren
On Tue, May 8, 2018 at 2:31 AM, Oleg Broytman wrote: >So anyone who wants to filter os.walk() must reimplement os.walk() > themselves instead of passing something like filter_dir and filter_file > (or accept_dir/accept_file) to os.walk()? Kind of painful, no? > ​Not really. It's pretty simp

Re: [Python-ideas] Please consider skipping hidden directories in os.walk, os.fwalk, etc.

2018-05-08 Thread David Mertz
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. I'd suggest meeting the ideas slightly and making the new argument 'filter'

Re: [Python-ideas] Please consider skipping hidden directories in os.walk, os.fwalk, etc.

2018-05-08 Thread Oleg Broytman
Hi! On Tue, May 08, 2018 at 07:12:35AM +, Yuval Greenfield wrote: > If you > want to avoid duplicate `stat` calls, you'll probably write: > > import os > import stat > def is_hidden(st): > return bool(st.st_file_attributes & stat.FILE_ATTRIBUTE_HIDDEN) > def visible_walk(path): > fo

Re: [Python-ideas] Please consider skipping hidden directories in os.walk, os.fwalk, etc.

2018-05-08 Thread Yuval Greenfield
On Mon, May 7, 2018 at 9:44 PM Steve Barnes wrote: > Since the implementation of os.walk has changed to use os.scandir which > exposes the returned file statuses in the os.DirEntry.stat() the > overhead should be minimal. > > An alternative would be to add another new function, say os.vwalk(), to

Re: [Python-ideas] Please consider skipping hidden directories in os.walk, os.fwalk, etc.

2018-05-08 Thread Steven D'Aprano
On Mon, May 07, 2018 at 06:05:15AM +, Steve Barnes wrote: > In a lot of uses of os.walk it is desirable to skip version control > directories, (which are usually hidden directories), to the point that > almost all of the examples given look like: > > import os > for root, dirs, files in os.w

[Python-ideas] Please consider skipping hidden directories in os.walk, os.fwalk, etc.

2018-05-07 Thread Steve Barnes
In a lot of uses of os.walk it is desirable to skip version control directories, (which are usually hidden directories), to the point that almost all of the examples given look like: import os for root, dirs, files in os.walk(some_dir): if 'CVS' in dirs: dirs.remove('CVS') # or .s