-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b86b954
Showing
6 changed files
with
265 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: Build and Package | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
runs-on: windows-latest | ||
|
||
strategy: | ||
matrix: | ||
python-version: [3.8] | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install dependencies | ||
run: pip install -r requirements.txt | ||
|
||
- name: Install PyInstaller | ||
run: pip install pyinstaller | ||
|
||
- name: Package with PyInstaller | ||
run: pyinstaller --onefile --name CleanSweep main.py | ||
|
||
- name: Archive results | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: exe-package | ||
path: dist/CleanSweep.exe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
# 前言 | ||
|
||
## 软件名称 | ||
|
||
CleanSweep | ||
|
||
## 中文使用说明和功能讲解 | ||
|
||
### 1. 软件介绍 | ||
|
||
CleanSweep 是一个用于清理Windows系统上无用文件和文件夹的小工具。该软件可以帮助用户释放硬盘空间,提升系统性能。它支持从本地txt文件中读取要删除的文件和文件夹路径,并且在删除操作前提示用户确认,确保删除操作的安全性。 | ||
|
||
### 2. 功能 | ||
|
||
读取路径文件:从用户提供的txt文件中读取要删除的文件和文件夹路径。 | ||
删除临时文件:删除指定路径下的临时文件、日志文件、备份文件等。 | ||
删除临时文件夹:删除指定路径下的临时文件夹、缓存文件夹等。 | ||
清空回收站:提示用户是否清空回收站。 | ||
日志记录:记录删除操作的详细信息,包括删除的文件和文件夹路径、删除失败的原因等。 | ||
|
||
### 3. 使用说明 | ||
|
||
#### 3.1. 准备路径文件 | ||
|
||
创建一个txt文件,例如 cleanup_paths.txt。 | ||
将要删除的文件和文件夹路径逐行写入该文件。 | ||
|
||
#### 3.2. 运行软件 | ||
|
||
确保系统安装了Python环境和pywin32库。可以通过以下命令安装pywin32:`pip install pywin32` | ||
运行以下Python脚本:`python main.py` | ||
|
||
输入包含要删除路径的txt文件路径,例如 C:\path\to\cleanup_paths.txt。 | ||
|
||
程序会逐行读取txt文件中的路径,并提示用户确认是否删除。如果用户确认删除,程序将删除相应的文件或文件夹,并记录日志。 | ||
|
||
程序还会提示用户是否清空回收站。 | ||
|
||
### 4. 注意事项 | ||
|
||
运行该程序需要管理员权限。 | ||
清空回收站功能需要安装pywin32库。 | ||
请确保在运行此程序之前了解它的作用,并在适当的时候进行备份。 | ||
删除操作不可逆,请谨慎确认删除操作。 | ||
通过CleanSweep,您可以轻松、安全地清理系统上的无用文件和文件夹,从而释放更多的硬盘空间,提升系统性能。 | ||
|
||
## 文件夹用途说明 | ||
|
||
### C:\Windows\Temp | ||
|
||
存储内容:临时文件,安装程序和系统过程创建的临时文件。 | ||
删除影响:通常可以安全删除,可能会导致正在进行的安装或更新失败。 | ||
|
||
### C:\Windows\Prefetch | ||
|
||
存储内容:Windows启动和程序启动时的预取文件,用于加速启动过程。 | ||
删除影响:删除后,启动速度可能暂时变慢,系统会重新生成这些文件。 | ||
|
||
### C:\Users%USERNAME%\AppData\Local\Temp | ||
|
||
存储内容:用户临时文件,由应用程序和系统过程创建的临时文件。 | ||
删除影响:通常可以安全删除,可能会导致正在运行的应用程序出现问题。 | ||
|
||
### C:\Users%USERNAME%\AppData\Local\Microsoft\Windows\INetCache | ||
|
||
存储内容:Internet Explorer和其他浏览器的缓存文件。 | ||
删除影响:删除后,浏览器会重新下载网页内容,可能会导致网站加载时间稍长。 | ||
|
||
### C:\Users%USERNAME%\AppData\Local\Microsoft\Windows\Explorer | ||
|
||
存储内容:文件资源管理器的缓存文件和临时数据。 | ||
删除影响:删除后,文件资源管理器可能需要重新生成缓存,但通常不会影响系统性能。 | ||
|
||
### C:\Users%USERNAME%\AppData\Local\CrashDumps | ||
|
||
存储内容:应用程序崩溃时生成的转储文件。 | ||
删除影响:删除后,无法用于诊断应用程序崩溃的问题,通常可以安全删除。 | ||
|
||
### C:\Users%USERNAME%\AppData\Local\Temp*.tmp | ||
|
||
存储内容:临时文件。 | ||
删除影响:通常可以安全删除。 | ||
|
||
### C:\Users%USERNAME%\AppData\Local\Temp*.log | ||
|
||
存储内容:日志文件。 | ||
删除影响:通常可以安全删除。 | ||
|
||
### C:\Users%USERNAME%\AppData\Local\Temp*.bak | ||
|
||
存储内容:备份文件。 | ||
删除影响:通常可以安全删除。 | ||
|
||
### C:\Users%USERNAME%\AppData\Local\Temp*.old | ||
|
||
存储内容:旧版本的文件。 | ||
删除影响:通常可以安全删除。 | ||
|
||
### C:\Users%USERNAME%\AppData\Local\Temp~* | ||
|
||
存储内容:临时文件。 | ||
删除影响:通常可以安全删除。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import os | ||
import shutil | ||
import logging | ||
|
||
# 配置日志记录 | ||
logging.basicConfig(filename='删除日志.txt', level=logging.INFO, | ||
format='%(asctime)s - %(levelname)s - %(message)s', encoding='utf-8') | ||
|
||
# 从txt文件中读取要删除的文件和文件夹路径 | ||
def read_paths_from_file(file_path): | ||
import chardet | ||
detected_encoding = chardet.detect(open(file_path, 'rb').read())['encoding'] | ||
with open(file_path, 'r', encoding=detected_encoding) as file: | ||
paths = [line.strip() for line in file if line.strip()] | ||
return paths | ||
|
||
# 获取路径的描述 | ||
def get_path_description(path): | ||
descriptions = { | ||
r'C:\Windows\Temp': "Windows临时文件夹,存储安装程序和系统过程创建的临时文件。", | ||
r'C:\Windows\Prefetch': "Windows预取文件夹,用于加速启动过程。", | ||
r'C:\Users\%USERNAME%\AppData\Local\Temp': "用户临时文件夹,存储应用程序和系统过程创建的临时文件。", | ||
r'C:\Users\%USERNAME%\AppData\Local\Microsoft\Windows\INetCache': "浏览器缓存文件夹,存储浏览器的缓存文件。", | ||
r'C:\Users\%USERNAME%\AppData\Local\Microsoft\Windows\Explorer': "文件资源管理器缓存文件夹,存储文件资源管理器的缓存文件。", | ||
r'C:\Users\%USERNAME%\AppData\Local\CrashDumps': "崩溃转储文件夹,存储应用程序崩溃时生成的转储文件。", | ||
r'C:\Users\%USERNAME%\AppData\Local\Temp\*.tmp': "临时文件。", | ||
r'C:\Users\%USERNAME%\AppData\Local\Temp\*.log': "日志文件。", | ||
r'C:\Users\%USERNAME%\AppData\Local\Temp\*.bak': "备份文件。", | ||
r'C:\Users\%USERNAME%\AppData\Local\Temp\*.old': "旧版本文件。", | ||
r'C:\Users\%USERNAME%\AppData\Local\Temp\~*': "临时文件。", | ||
} | ||
return descriptions.get(path, "未知路径") | ||
|
||
# 删除文件 | ||
def delete_file(file): | ||
try: | ||
os.remove(file) | ||
logging.info(f"已删除文件: {file} - {get_path_description(file)}") | ||
print(f"已删除文件: {file}") | ||
except Exception as e: | ||
logging.error(f"删除文件失败: {file}。原因: {e}") | ||
print(f"删除文件失败: {file}。原因: {e}") | ||
|
||
# 删除目录 | ||
def delete_directory(directory): | ||
try: | ||
shutil.rmtree(directory) | ||
logging.info(f"已删除目录: {directory} - {get_path_description(directory)}") | ||
print(f"已删除目录: {directory}") | ||
except Exception as e: | ||
logging.error(f"删除目录失败: {directory}。原因: {e}") | ||
print(f"删除目录失败: {directory}。原因: {e}") | ||
|
||
# 清理指定的路径 | ||
def clean_paths(paths): | ||
for path in paths: | ||
# 处理路径中的环境变量,例如 %USERNAME% | ||
path = os.path.expandvars(path) | ||
|
||
if os.path.exists(path): | ||
description = get_path_description(path) | ||
confirm = input(f"是否删除路径 {path} ({description})? (y/n): ") | ||
if confirm.lower() == 'y': | ||
if os.path.isfile(path): | ||
delete_file(path) | ||
elif os.path.isdir(path): | ||
delete_directory(path) | ||
else: | ||
print(f"未知类型的路径: {path}") | ||
else: | ||
logging.info(f"跳过清理路径: {path}") | ||
print(f"跳过清理路径: {path}") | ||
else: | ||
logging.warning(f"路径不存在: {path}") | ||
print(f"路径不存在: {path}") | ||
|
||
# 清空回收站 | ||
def empty_recycle_bin(): | ||
try: | ||
import win32com.client | ||
shell = win32com.client.Dispatch("Shell.Application") | ||
recycle_bin = shell.NameSpace(10) | ||
recycle_bin_items = recycle_bin.Items() | ||
item_count = recycle_bin_items.Count | ||
if item_count > 0: | ||
confirm = input(f"回收站中有 {item_count} 个项目。是否清空回收站? (y/n): ") | ||
if confirm.lower() == 'y': | ||
shell.NameSpace(10).Items().InvokeVerb("empty") | ||
logging.info(f"已清空回收站中的 {item_count} 个项目。") | ||
print(f"已删除回收站中的 {item_count} 个项目。") | ||
else: | ||
logging.info("跳过清空回收站。") | ||
print("回收站未清空。") | ||
else: | ||
logging.info("回收站已为空。") | ||
print("回收站已为空。") | ||
except ImportError: | ||
logging.error("未安装pywin32库,无法清空回收站。") | ||
print("未安装pywin32库,无法清空回收站。") | ||
|
||
# 执行清理 | ||
if __name__ == "__main__": | ||
file_path = input("请输入包含要删除路径的txt文件路径(默认:清理配置.txt): ") | ||
if file_path == '': | ||
file_path = "清理配置.txt" | ||
if os.path.isfile(file_path): | ||
paths_to_clean = read_paths_from_file(file_path) | ||
clean_paths(paths_to_clean) | ||
empty_recycle_bin() | ||
else: | ||
print("输入的文件路径无效。") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
pywin32 | ||
chardet | ||
shutil | ||
logging |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
C:\Windows\Temp | ||
C:\Users\%USERNAME%\AppData\Local\CrashDumps | ||
C:\Users\%USERNAME%\AppData\Local\Temp\*.tmp | ||
C:\Users\%USERNAME%\AppData\Local\Temp\*.log | ||
C:\Users\%USERNAME%\AppData\Local\Temp\*.bak | ||
C:\Users\%USERNAME%\AppData\Local\Temp\*.old | ||
C:\Users\%USERNAME%\AppData\Local\Temp\~* |