python递归删除空目录

python递归删除空目录:

vi a1.py

#!/usr/bin/python

import os

dir="/root/python"

for root,dirs,files in os.walk(dir):
for f in dirs:
if not os.listdir(os.path.join(root,f)):
os.removedirs(os.path.join(root,f))

:wq

python a1.py

猜你喜欢

转载自blog.51cto.com/yangzhiming/2128708