-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcleaner.py
More file actions
28 lines (23 loc) · 933 Bytes
/
Copy pathcleaner.py
File metadata and controls
28 lines (23 loc) · 933 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import os
import shutil
def clean_python_cache(root_dir: str = ".") -> None:
"""Supprime tous les dossiers __pycache__ et fichiers .pyc dans le projet."""
removed_dirs = 0
removed_files = 0
for dirpath, dirnames, filenames in os.walk(root_dir):
# Supprime __pycache__ si présent
if "__pycache__" in dirnames:
cache_dir = os.path.join(dirpath, "__pycache__")
shutil.rmtree(cache_dir)
removed_dirs += 1
dirnames.remove("__pycache__") # pour ne pas parcourir dedans
# Supprime tous les .pyc
for f in filenames:
if f.endswith(".pyc"):
file_path = os.path.join(dirpath, f)
os.remove(file_path)
removed_files += 1
print(f"✅ Supprimé {removed_dirs} dossiers __pycache__ et {removed_files} fichiers .pyc")
# Utilisation
if __name__ == "__main__":
clean_python_cache()