Roy Smith wrote:

> In article <c4gjqvf8cm...@mid.individual.net>,
>  Gregory Ewing <greg.ew...@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.

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to