Created
August 9, 2017 06:50
-
-
Save revotu/93d6508a2755513337f1252cd3a1b62c to your computer and use it in GitHub Desktop.
Python Recursively Remove Empty Directories
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Recursively Remove Empty Directories | |
import os | |
for root, dirs, files in os.walk(path, topdown=False): | |
if not files and not dirs: | |
os.rmdir(root) | |
#Recursively Remove Empty Directories, During do something like os.remove(file) | |
import os | |
for root, dirs, files in os.walk(path, topdown=False): | |
# do something like os.remove(file) | |
if not os.listdir(root): | |
os.rmdir(root) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
reference from : Python如何递归删除空文件夹