Last active
April 11, 2019 07:09
-
-
Save void32/9122493ae451f889f2a7c3f2f51cfcf1 to your computer and use it in GitHub Desktop.
Recursively remove paths as rm -rf [FILE]...
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
import glob | |
import os | |
import shutil | |
def rm_rf(path): | |
""" 'rm -rf' in Python """ | |
fp_list = glob.glob(path) | |
for fp in fp_list: | |
if os.path.islink(fp): | |
os.remove(fp) | |
elif os.path.isdir(fp): | |
shutil.rmtree(fp) | |
else: | |
os.remove(fp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment