[BangPypers] parsing directory and subdirecties

Dhananjay Nene dhananjay.nene at gmail.com
Thu Nov 18 18:26:51 CET 2010


On Thu, Nov 18, 2010 at 10:46 AM, Kenneth Gonsalves <lawgon at au-kbc.org>wrote:

> On Thu, 2010-11-18 at 10:26 +0530, Asokan Pichai wrote:
> > On 18 November 2010 09:35, Nitin Kumar <nitin.nitp at gmail.com> wrote:
> > > hi all,
> > >
> > > is there any simple way where a can parse into directory and
> > subdirectories
> > > to get the detail of files and count.
> >
> > Check if os.walk() is useful.
>
> but that is looping - which he does not want.
>

Am unclear by what specifically is the issue here with looping, but list
comprehensions can be quite useful (even though implicitly they use
iterators as do loops).
Something along the lines of

print list((dirpath, len(filenames)) for dirpath, dirnames, filenames in
os.walk('/home/user'))

> --
> regards
> Kenneth Gonsalves
>
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> http://mail.python.org/mailman/listinfo/bangpypers
>



-- 
--------------------------------------------------------
blog: http://blog.dhananjaynene.com
twitter: http://twitter.com/dnene


More information about the BangPypers mailing list