Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news2.arglkargh.de!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Gregory Ewing 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 18:14:54 +1200 Lines: 28 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net Gcngr1WyZu9dXHKtS/FO5wYNH58IvMoGno3YC/PmAWBL16OWMo Cancel-Lock: sha1:ygLTjvvHG941gCmeKBDsWbAvVUo= User-Agent: Mozilla Thunderbird 1.0.5 (Macintosh/20050711) X-Accept-Language: en-us, en In-Reply-To: Xref: csiph.com comp.lang.python:75835 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. -- Greg