Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Re: Removing hidden directory in os.walk() (http://www.velocityreviews.com/forums/t744193-re-removing-hidden-directory-in-os-walk.html)

Chris Rebert 02-25-2011 05:52 PM

Re: Removing hidden directory in os.walk()
 
On Fri, Feb 25, 2011 at 9:40 AM, Gaƫtan Podevijn <gpodevij@gmail.com> wrote:
> Hello,
> I would like that os.walk() does not walk through hidden directories. I know
> that with topdow = true, I can modify the subdirectory list in place, but
> how should I remove every hidden directory from this place in list ?


Assuming you're on *nix:

for dirpath, dirnames, filenames in os.walk(top):
dirnames[:] = [d for d in dirnames if not d.startswith('.')]
do_whatever()

Cheers,
Chris
--
http://blog.rebertia.com


All times are GMT. The time now is 04:48 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.