Deleting empty folders.
Padraig at Linux.ie
Padraig at Linux.ie
Fri Feb 7 11:06:58 EST 2003
keithk wrote:
> Hi All,
>
> I want to write a short script that checks whether a set of windows
> folders is empty and then if they are , delete them, I am unable to find
> a module in python which checks whether a folder is empty, could someone
> please point me in the right direction,
>
> thanks in advance,
How about:
import os
l=[]
def make_list(arg, dirn, arg):
l.append(dirn)
os.path.walk("mydir", make_list, None)
l.reverse()
for dirn in l:
try:
rmdir()
except:
pass #probably not empty
More information about the Python-list
mailing list