-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcleanup.py
66 lines (56 loc) · 2.31 KB
/
cleanup.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
import os
import sys
import time
import ctypes
import re
import shutil
import tempfile
ctypes.windll.kernel32.SetConsoleTitleW("SplinterForge Bot Cleanup Script")
def process():
try:
os.system("taskkill /im chromedriver.exe /f")
os.system("taskkill /im chrome.exe /f")
os.system("taskkill /im python.exe /f")
except:
print("Error Encountered while running script")
def clean():
cache_dir = tempfile.gettempdir() + "\\chromedriver\\Cache"
if os.path.exists(cache_dir):
shutil.rmtree(cache_dir)
profile_dir = tempfile.gettempdir() + "\\chromedriver\\Profile"
if os.path.exists(profile_dir):
shutil.rmtree(profile_dir)
chromedriver_exe = tempfile.gettempdir() + "\\chromedriver.exe"
if os.path.exists(chromedriver_exe):
os.remove(chromedriver_exe)
program_files = "C:\\Program Files (x86)"
for dirpath, dirnames, filenames in os.walk(program_files):
for dirname in dirnames:
if re.match(r"^scoped_dir\d+_\d+$", dirname):
dir_path = os.path.join(dirpath, dirname)
try:
shutil.rmtree(dir_path)
print(f"Deleted directory: {dir_path}")
except Exception as e:
print(f"Failed to delete directory: {dir_path}")
print(f"Error: {e}")
temp_directory = os.environ["TEMP"]
for filename in os.listdir(temp_directory):
file_path = os.path.join(temp_directory, filename)
try:
if os.path.isfile(file_path):
os.unlink(file_path)
elif os.path.isdir(file_path):
shutil.rmtree(file_path)
except Exception as e:
print(f"Failed to delete file or directory: {file_path}")
print(f"Error: {e}")
print("Please make sure you are ok about cleaning up all chrome.exe, chromedriver.exe, python.exe process currently running in this computer and also files were generated from running the bot, which means SplinterForge Bot, any running chrome browser, and this script will be closing after performed. please type 'yes' and then press 'ENTER' on keyboard to confirm:")
text = input().lower()
if text == "yes":
clean()
process()
else:
print("Cleanup cancelled... Exit in 5 seconds...")
time.sleep(5)
sys.exit()