-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcleanup_unity.py
56 lines (49 loc) · 1.95 KB
/
cleanup_unity.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import os
import shutil
import re
import argparse
def cleanup_unity_project(root_dir):
"""Cleans up Unity-generated files and folders."""
unity_generated_patterns = [
r"^Library$",
r"^Build$",
r"^build$",
r"^Builds$",
r"^builds$",
r"^Temp$",
r"^temp$",
r"^__pycache__$",
r"\.csproj$", # Corrected: Escape the dot
r"\.sln$", # Corrected: Escape the dot
r"\.suo$", # Corrected: Escape the dot
r"\.userprefs$", # Corrected: Escape the dot
# r"\.meta$", # Be very cautious with .meta files!
r"\.unity.lock$", # Corrected: Escape the dots
r"^obj$",
]
for dirpath, dirnames, filenames in os.walk(root_dir):
for item_name in dirnames + filenames:
for pattern in unity_generated_patterns:
if re.match(pattern, item_name):
item_path = os.path.join(dirpath, item_name)
try:
if os.path.isdir(item_path):
print(f"Deleting directory: {item_path}")
shutil.rmtree(item_path)
if item_name in dirnames:
dirnames.remove(item_name)
elif os.path.isfile(item_path):
print(f"Deleting file: {item_path}")
os.remove(item_path)
except OSError as e:
print(f"Error deleting {item_path}: {e}")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Clean up Unity-generated files and folders.")
parser.add_argument("directory", help="The root directory of the Unity project.")
args = parser.parse_args()
root_directory = args.directory
if not os.path.exists(root_directory):
print(f"Error: Directory '{root_directory}' not found.")
else:
cleanup_unity_project(root_directory)
print("Cleanup finished.")