Deleting empty folders.

Piet van Oostrum piet at
Sat Feb 8 16:13:16 CET 2003

>>>>> keithk <member21858 at> (K) wrote:

K> Hi All,

K> I want to write a short script that checks whether a set of windows
K> folders is empty and then if they are , delete them, I am unable to find
K> a module in python which checks whether a folder is empty, could someone
K> please point me in the right direction,

Use os.listdir() and check if you get an empty list.
By the way, if you use os.rmdir(), it will only delete the directory if it
is empty, otherwise it raises an exception.
Piet van Oostrum <piet at>
Private email: P.van.Oostrum at

More information about the Python-list mailing list