Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!nntp.club.cc.cmu.edu!micro-heart-of-gold.mit.edu!bloom-beacon.mit.edu!bloom-beacon.mit.edu!panix!roy From: Roy Smith Newsgroups: comp.lang.python Subject: Re: Test for an empty directory that could be very large if it is not empty? Date: Thu, 07 Aug 2014 07:54:48 -0400 Organization: PANIX Public Access Internet and UNIX, NYC Lines: 30 Message-ID: References: NNTP-Posting-Host: localhost X-Trace: reader1.panix.com 1407412488 10865 127.0.0.1 (7 Aug 2014 11:54:48 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Thu, 7 Aug 2014 11:54:48 +0000 (UTC) User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) Xref: csiph.com comp.lang.python:75844 In article , Gregory Ewing 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?