-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclear_recycling_bin.py
More file actions
64 lines (52 loc) · 2.05 KB
/
clear_recycling_bin.py
File metadata and controls
64 lines (52 loc) · 2.05 KB
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
import json
import platform
import os
import ctypes
import asyncio
PLATFORM = platform.system().lower()
def get_recycle_bin_size():
# Note: Without winshell, we can't get the exact count
# but we can check if the operation was successful
return None
async def func(args):
try:
print("\n=== Starting Recycle Bin Cleaner ===")
if PLATFORM != "windows":
error_msg = f"Unsupported platform: {PLATFORM}"
print(f"Error: {error_msg}")
return json.dumps({"error": "This script only works on Windows systems"})
# Check if running with admin rights
is_admin = ctypes.windll.shell32.IsUserAnAdmin()
print(f"Admin privileges: {'Yes' if is_admin else 'No'}")
print("\nAttempting to clear recycle bin...")
success = False
try:
# Use shell32 to empty the recycle bin
result = ctypes.windll.shell32.SHEmptyRecycleBinW(None, None, 0)
if result == 0: # 0 indicates success
success = True
message = "Recycle bin cleared successfully!"
else:
message = f"Failed to clear recycle bin. Error code: {result}"
except Exception as e:
message = f"Error clearing recycle bin: {str(e)}"
print(f"\nResult: {message}")
print("=== Operation Complete ===\n")
return json.dumps({
"message": message,
"admin_rights": bool(is_admin),
"success": success
})
except Exception as e:
error_msg = f"Error in main function: {str(e)}"
print(f"\nError: {error_msg}")
return json.dumps({"error": str(e)})
object = {
"name": "clearRecycleBin",
"description": "Clears the Windows Recycle Bin without confirmation prompts. Creates a detailed log file in the same directory. Requires administrator privileges for best results.",
"parameters": {
"type": "object",
"properties": {},
"required": []
}
}