Skip to content

Instantly share code, notes, and snippets.

@void32
Last active April 11, 2019 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save void32/9122493ae451f889f2a7c3f2f51cfcf1 to your computer and use it in GitHub Desktop.
Save void32/9122493ae451f889f2a7c3f2f51cfcf1 to your computer and use it in GitHub Desktop.
Recursively remove paths as rm -rf [FILE]...
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