Skip to content

Instantly share code, notes, and snippets.

@thepushkarp
Last active June 5, 2023 15:29
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 thepushkarp/1e105b9a04de83b45a7d7ad70d1fa938 to your computer and use it in GitHub Desktop.
Save thepushkarp/1e105b9a04de83b45a7d7ad70d1fa938 to your computer and use it in GitHub Desktop.
Deletes unnecessary folders that take huge space. Useful when moving directories.
import os
import shutil
def delete_folders(path):
for root, dirs, files in os.walk(path):
if 'node_modules' in dirs:
shutil.rmtree(os.path.join(root, 'node_modules'))
print(f"Deleted node_modules folder in {root}")
if '.next' in dirs:
shutil.rmtree(os.path.join(root, '.next'))
print(f"Deleted .next folder in {root}")
if 'venv' in dirs:
shutil.rmtree(os.path.join(root, 'venv'))
print(f"Deleted venv folder in {root}")
if 'build' in dirs:
shutil.rmtree(os.path.join(root, 'build'))
print(f"Deleted build folder in {root}")
if 'env' in dirs:
shutil.rmtree(os.path.join(root, 'env'))
print(f"Deleted env folder in {root}")
if '.vscode' in dirs:
shutil.rmtree(os.path.join(root, '.vscode'))
print(f"Deleted .vscode folder in {root}")
if '__pycache__' in dirs:
shutil.rmtree(os.path.join(root, '__pycache__'))
print(f"Deleted __pycache__ folder in {root}")
if '.pytest_cache' in dirs:
shutil.rmtree(os.path.join(root, '.pytest_cache'))
print(f"Deleted .pytest_cache folder in {root}")
if '.idea' in dirs:
shutil.rmtree(os.path.join(root, '.idea'))
print(f"Deleted .idea folder in {root}")
if 'temp' in dirs:
shutil.rmtree(os.path.join(root, 'temp'))
print(f"Deleted temp folder in {root}")
if __name__ == '__main__':
delete_folders('.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment