How to determine that if a folder is empty?
sjmachin at lexicon.net
Mon Aug 8 14:04:35 CEST 2005
Reinhold Birkenfeld wrote:
> could ildg wrote:
>>I want to check if a folder named "foldername" is empty.
>>I use os.listdir(foldername)== to do this,
>>but it will be very slow if the folder has a lot of sub-files.
>>Is there any efficient ways to do this?
> empty = True
> except OSError:
> empty = False
> should be efficient.
But it removes the folder if it is empty. Perhaps it's not efficient to
create the folder again.
More information about the Python-list