-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTemporary Files Cleaner.py
68 lines (51 loc) · 2.12 KB
/
Temporary Files Cleaner.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
57
58
59
60
61
62
63
64
65
66
67
68
try:
import ctypes
import shutil
import colorama
except ModuleNotFoundError as e:
modulename = str(e).split("No module named ")[1].replace("'", "")
input(f"Please install module with: pip install {modulename}")
exit()
import os
from colorama import Fore, init
init(convert=True)
def main():
ctypes.windll.kernel32.SetConsoleTitleW(
"Temporary Files Cleaner | v0.1 | By Tayz")
folders = [os.environ.get('TEMP').replace("\\", "/"),
os.environ.get("USERPROFILE").replace("\\", "/") + "/Downloads"]
deleteFileCount = 0
deleteFolderCount = 0
for folder in folders:
choice = input(
f"Do you want clear files and folders in {folder} (y/n) ? ")
if str(choice) == "yes" or str(choice) == "y":
if not os.listdir(folder):
print(f'{Fore.RED}No folders/files{Fore.RESET}\n')
else:
for the_file in os.listdir(folder):
file_path = os.path.join(folder, the_file)
indexNo = file_path.find('\\')
itemName = file_path[indexNo+1:]
try:
if os.path.isfile(file_path):
os.unlink(file_path)
print(
f'{Fore.GREEN}File deleted{Fore.RESET} {itemName}')
deleteFileCount += 1
elif os.path.isdir(file_path):
if file_path.__contains__('chocolatey'):
continue
shutil.rmtree(file_path)
print(
f'{Fore.GREEN}Folder deleted{Fore.RESET} {itemName}')
deleteFolderCount += 1
except Exception as e:
print(f'{Fore.RED}Access Denied{Fore.RESET} {itemName}')
print()
else:
print()
input(str(deleteFileCount) + ' files and ' +
str(deleteFolderCount) + ' folders deleted. Press enter to exit')
if __name__ == "__main__":
main()