python 겹 쳐 서 빈 폴 더 삭제

662 단어 python

import os, os.path
import stat


BASE_FOLDER = r'C:\MessageStorage'

fl = os.listdir

def delFolder(folder):
	fl = os.listdir(folder)
	#print fl
	if 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)

좋은 웹페이지 즐겨찾기