Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #75815 > unrolled thread
| Started by | Tim Chase <python.list@tim.thechases.com> |
|---|---|
| First post | 2014-08-06 17:44 -0500 |
| Last post | 2014-08-06 17:44 -0500 |
| 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.
Re: Test for an empty directory that could be very large if it is not empty? Tim Chase <python.list@tim.thechases.com> - 2014-08-06 17:44 -0500
| From | Tim Chase <python.list@tim.thechases.com> |
|---|---|
| Date | 2014-08-06 17:44 -0500 |
| Subject | Re: Test for an empty directory that could be very large if it is not empty? |
| Message-ID | <mailman.12713.1407365165.18130.python-list@python.org> |
On 2014-08-07 08:26, Ben Finney wrote:
> Virgil Stokes <vs@it.uu.se> writes:
> > Suppose I have a directory C:/Test that is either empty or
> > contains more than 2000000 files, all with the same extension
> > (e.g. *.txt). How can I determine if the directory is empty
> > WITHOUT the generation of a list of the file names in it (e.g.
> > using os.listdir('C:/Test')) when it is not empty?
>
> Certainly ‘os.listdir(foo)’ is the simplest way to determine the
> entries in a directory, and thereby to test whether it is empty.
> That simplicity is very valuable, and you should have a compelling,
> *measured* reason to do something more complicated. What is it?
With all the changes in 2->3 where many listy things were made into
iteratory things (e.g. range()), I was surprised that os.listdir()
didn't do likewise since I believe that just about every OS uses some
iterator-like call behind the scenes anyways.
The difference in timings when serving a web-request are noticeable
(in my use-case, I had to change my algorithm and storage structure
to simplify/avoid heavily-populated directories)
-tkc
Back to top | Article view | comp.lang.python
csiph-web