python 层叠删空文件夹
import os, os.pathimport statBASE_FOLDER = r'C:\MessageStorage'fl = os.listdirdef delFolder(folder):fl = os.listdir(folder)#print flif len(fl) == 0:os.rmdir(folder)print "deleted folder"return;else:os.chdir(folder)for f in fl:if os.path.isdir(f):delFolder(os.path.join(folder, f))os.chdir('..')fl = os.listdir(folder)if len(fl) == 0:os.rmdir(folder)print "deleted folder"delFolder(BASE_FOLDER)