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


Groups > comp.lang.python > #75845

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!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!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; 'created,': 0.09; 'here?': 0.09; 'newly': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'windows,': 0.09; 'python': 0.11; 'assume': 0.14; 'be:': 0.16; 'empty.': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'roy': 0.16; 'sure.': 0.16; 'wrote:': 0.18; 'module': 0.19; 'properly': 0.19; 'header:User- Agent:1': 0.23; 'directory.': 0.24; 'large,': 0.24; 'new,': 0.24; 'fairly': 0.24; 'nearly': 0.26; 'header:X-Complaints-To:1': 0.27; 'unix': 0.29; 'wonder': 0.29; "doesn't": 0.30; 'subject:that': 0.31; 'file': 0.32; 'probably': 0.32; 'could': 0.34; "can't": 0.35; 'no,': 0.35; 'really': 0.36; 'subject:?': 0.36; 'should': 0.36; 'list': 0.37; 'to:addr:python-list': 0.38; 'files': 0.38; 'reported': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'tell': 0.60; 'new': 0.61; 'strategy': 0.64; 'between': 0.67; 'determine': 0.67; 'smith': 0.68; 'therefore': 0.72; 'article': 0.77; 'deleted?': 0.84; 'obvious.': 0.84; 'subject:Test': 0.84; 'viable': 0.84; 'wrap.': 0.84; 'lazy': 0.91; 'subject:very': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Peter Otten <__peter__@web.de>
Subject Re: Test for an empty directory that could be very large if it is not empty?
Date Thu, 07 Aug 2014 14:06:14 +0200
Organization None
References <mailman.12711.1407363468.18130.python-list@python.org> <c4gjqvF8cmiU1@mid.individual.net> <roy-B1A7CD.07544807082014@news.panix.com>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Gmane-NNTP-Posting-Host p57bda2d3.dip0.t-ipconnect.de
User-Agent KNode/4.13.2
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.12724.1407413193.18130.python-list@python.org> (permalink)
Lines 36
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1407413193 news.xs4all.nl 2885 [2001:888:2000:d::a6]:56259
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:75845

Show key headers only | View raw


Roy Smith wrote:

> In article <c4gjqvF8cmiU1@mid.individual.net>,
>  Gregory Ewing <greg.ewing@canterbury.ac.nz> wrote:
> 
>> Virgil Stokes wrote:
>> > How can I
>> > determine if the directory is empty WITHOUT the generation of a list of
>> > the file names
>> 
>> Which platform?
>> 
>> On Windows, I have no idea.
>> 
>> On Unix you can't really do this properly without access
>> to opendir() and readdir(), which Python doesn't currently
>> wrap.
>> 
>> Will the empty directories be newly created, or could they
>> be ones that *used* to contain 200000 files that have since
>> been deleted?
>> 
>> If they're new or nearly new, you could probably tell from
>> looking at the size reported by stat() on the directory.
>> The difference between a fresh empty directory and one with
>> 200000 files in it should be fairly obvious.
>> 
>> A viable strategy might be: If the directory is very large,
>> assume it's not empty. If it's smallish, list its contents
>> to find out for sure.
> 
> I wonder if glob.iglob('*') might help here?

No, the glob module uses os.listdir() under the hood. Therefore iglob() is 
lazy for multiple directories only.

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


Thread

Test for an empty directory that could be very large if it is not empty? Virgil Stokes <vs@it.uu.se> - 2014-08-06 23:46 +0200
  Re: Test for an empty directory that could be very large if it is not   empty? Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-08-07 18:14 +1200
    Re: Test for an empty directory that could be very large if it is not   empty? Cameron Simpson <cs@zip.com.au> - 2014-08-07 17:08 +1000
    Re: Test for an empty directory that could be very large if it is not   empty? Roy Smith <roy@panix.com> - 2014-08-07 07:54 -0400
      Re: Test for an empty directory that could be very large if it is not empty? Peter Otten <__peter__@web.de> - 2014-08-07 14:06 +0200
      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-07 07:05 -0500
        Re: Test for an empty directory that could be very large if it is not empty? Roy Smith <roy@panix.com> - 2014-08-07 08:19 -0400
          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-07 12:37 -0500
            Re: Test for an empty directory that could be very large if it is not empty? Roy Smith <roy@panix.com> - 2014-08-07 21:10 -0400
  Re: Test for an empty directory that could be very large if it is not empty? John Gordon <gordon@panix.com> - 2014-08-07 20:15 +0000

csiph-web