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


Groups > comp.lang.python > #75848

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!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.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.009
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'subject:not': 0.03; 'suppose': 0.07; 'none)': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'url:github': 0.09; 'def': 0.12; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'header:User-Agent:1': 0.23; 'extension': 0.26; 'header:X -Complaints-To:1': 0.27; 'subject:that': 0.31; 'writes:': 0.31; 'file': 0.32; '(e.g.': 0.33; 'subject:?': 0.36; 'list': 0.37; 'skip:o 20': 0.38; 'message-id:@gmail.com': 0.38; 'to:addr:python- list': 0.38; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'how': 0.40; 'more': 0.64; 'determine': 0.67; 'subject:Test': 0.84; 'received:89': 0.85; 'subject:very': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Akira Li <4kir4.1i@gmail.com>
Subject Re: Test for an empty directory that could be very large if it is not empty?
Date Thu, 07 Aug 2014 16:19:19 +0400
References <53E2A22A.10906@it.uu.se>
Mime-Version 1.0
Content-Type text/plain
X-Gmane-NNTP-Posting-Host 89.169.229.68
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)
Cancel-Lock sha1:CFgACsTJ1eto6uOyxaqt90ndUGs=
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.12726.1407413974.18130.python-list@python.org> (permalink)
Lines 17
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1407413974 news.xs4all.nl 2938 [2001:888:2000:d::a6]:33576
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:75848

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?

  def is_empty_dir(dirpath):
      return next(scandir(dirpath), None) is None

 https://github.com/benhoyt/scandir


 --
 Akira

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


Thread

Re: Test for an empty directory that could be very large if it is not empty? Akira Li <4kir4.1i@gmail.com> - 2014-08-07 16:19 +0400

csiph-web