如何自制清理垃圾软件

时间:2025-01-27 03:47:27 主机游戏

方法一:使用Python编写脚本

打开记事本或任何文本编辑器 ,如Notepad++或Visual Studio Code。

复制并粘贴以下Python代码

```python

import os

import shutil

指定需要清理的路径

temp_dir = "C:\\Users\\YourUsername\\AppData\\Local\\Temp"

清理临时文件

for filename in os.listdir(temp_dir):

file_path = os.path.join(temp_dir, filename)

try:

if os.path.isfile(file_path) or os.path.islink(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_path}. Reason: {e}')

```

将文件保存为`clean_temp.py`。

在命令提示符中运行`python clean_temp.py`。

方法二:创建批处理文件(.bat)

打开记事本或任何文本编辑器,如Notepad++或Visual Studio Code。

复制并粘贴以下批处理代码