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


Groups > comp.lang.python > #75814

Re: Test for an empty directory that could be very large if it is not empty?

From Ben Finney <ben+python@benfinney.id.au>
Subject Re: Test for an empty directory that could be very large if it is not empty?
Date 2014-08-07 08:26 +1000
References <53E2A22A.10906@it.uu.se>
Newsgroups comp.lang.python
Message-ID <mailman.12712.1407364031.18130.python-list@python.org> (permalink)

Show all headers | View raw


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?

What is your goal for that? Have you measured the performance difference
and decided *based on objective observation* that it's too expensive?

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?

-- 
 \         “The most dangerous man to any government is the man who is |
  `\       able to think things out for himself, without regard to the |
_o__)          prevailing superstitions and taboos.” —Henry L. Mencken |
Ben Finney

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: Test for an empty directory that could be very large if it is not empty? Ben Finney <ben+python@benfinney.id.au> - 2014-08-07 08:26 +1000
  Re: Test for an empty directory that could be very large if it is not empty? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-07 13:25 +1000

csiph-web