Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #93020 > unrolled thread

Re: Simplest/Idiomatic way to count files in a directory (using pathlib)

Started byTravis Griggs <travisgriggs@gmail.com>
First post2015-06-22 15:33 -0700
Last post2015-06-22 15:33 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Simplest/Idiomatic way to count files in a directory (using pathlib) Travis Griggs <travisgriggs@gmail.com> - 2015-06-22 15:33 -0700

#93020 — Re: Simplest/Idiomatic way to count files in a directory (using pathlib)

FromTravis Griggs <travisgriggs@gmail.com>
Date2015-06-22 15:33 -0700
SubjectRe: Simplest/Idiomatic way to count files in a directory (using pathlib)
Message-ID<mailman.713.1435012407.13271.python-list@python.org>
<I should proof my posts before I send them, sorry>

Subject nearly says it all.

If i’m using pathlib, what’s the simplest/idiomatic way to simply count how many files are in a given directory?

I was surprised (at first) when

   len(self.path.iterdir())

didn’t work.

I don’t see anything in the .stat() object that helps me.

I could of course do the 4 liner:

   count = 0
   for _ in self.path.iterdir():
       count += 1
   return count

The following seems to obtuse/clever for its own good:

   return sum(1 for _ in self.path.iterdir())

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web