- Notifications
You must be signed in to change notification settings - Fork 166
/
Copy pathremove_pycache_and_empty_dirs.py
29 lines (23 loc) · 1.08 KB
/
remove_pycache_and_empty_dirs.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
# This file has been modified by the Nextpy Team in 2023 using AI tools and automation scripts.
# We have rigorously tested these modifications to ensure reliability and performance. Based on successful test results, we are confident in the quality and stability of these changes.
"""Script to remove `__pycache__` and empty directories from a specified path.
Useful for post-test cleanups and maintaining a tidy workspace.
"""
importos
importshutil
defremove_pycache_and_empty_dirs(path: str):
"""Removes `__pycache__` folders and empty directories from the given path.
Args:
path (str): Directory path to clean up.
"""
forroot, dirs, _filesinos.walk(path, topdown=False):
# Remove `__pycache__` and empty directories
fordirindirs:
ifdir=='__pycache__':
shutil.rmtree(os.path.join(root, dir))
ifnotos.listdir(root) androot!=path:
os.rmdir(root)
if__name__=="__main__":
current_directory=os.getcwd()
remove_pycache_and_empty_dirs(current_directory)
print("Cleanup completed.")