Skip to content

Instantly share code, notes, and snippets.

@kerolloz
Created December 9, 2018 22:26
Show Gist options
  • Save kerolloz/53eeada4188a1c3cd6960c299132a2f5 to your computer and use it in GitHub Desktop.
Save kerolloz/53eeada4188a1c3cd6960c299132a2f5 to your computer and use it in GitHub Desktop.
remove files in current directory recursively (including inner directories)
import os
def remove_files_in_dir(deleted_filename):
for filename in os.listdir("."):
if os.path.isdir(filename):
os.chdir("./"+filename)
remove_files_in_dir(deleted_filename)
os.chdir("..")
if filename.endswith(deleted_filename):
print(filename, "deleted !")
os.remove(filename)
if __name__ == '__main__':
remove_files_in_dir("style.css")
remove_files_in_dir("script.js")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment