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?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.032
X-Spam-Evidence '*H*': 0.94; '*S*': 0.00; 'subject:not': 0.03; 'that?': 0.05; 'suppose': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'empty.': 0.16; 'finney': 0.16; 'measured': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'simplest': 0.16; 'thereby': 0.16; 'header:User-Agent:1': 0.23; 'certainly': 0.24; 'entries': 0.24; 'extension': 0.26; 'header:X-Complaints-To:1': 0.27; 'directory,': 0.31; 'subject:that': 0.31; 'writes:': 0.31; 'file': 0.32; '(e.g.': 0.33; 'something': 0.35; 'test': 0.35; 'subject:?': 0.36; 'should': 0.36; 'too': 0.37; 'list': 0.37; 'performance': 0.37; 'skip:o 20': 0.38; 'ben': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'how': 0.40; '8bit%:29': 0.60; 'dangerous': 0.60; 'most': 0.60; 'decided': 0.64; 'more': 0.64; 'determine': 0.67; 'goal': 0.75; 'himself,': 0.84; 'prevailing': 0.84; 'received:125': 0.84; 'subject:Test': 0.84; 'subject:very': 0.91; '\xe2\x80\x9cthe': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
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 Thu, 07 Aug 2014 08:26:49 +1000
References <53E2A22A.10906@it.uu.se>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 8bit
X-Gmane-NNTP-Posting-Host jigong.madmonks.org
X-Public-Key-ID 0xAC128405
X-Public-Key-Fingerprint 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405
X-Public-Key-URL http://www.benfinney.id.au/contact/bfinney-pubkey.asc
X-Post-From Ben Finney <bignose+hates-spam@benfinney.id.au>
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)
Cancel-Lock sha1:mMWH4qQZ+0OLwyUH2fJUZ2Ez0Y4=
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.12712.1407364031.18130.python-list@python.org> (permalink)
Lines 22
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1407364031 news.xs4all.nl 2873 [2001:888:2000:d::a6]:58771
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:75814

Show key headers only | 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