up
This commit is contained in:
commit
fbc84427d6
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
__pycache__/
|
71
config.py
Normal file
71
config.py
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
# -*- coding: UTF-8 -*-
|
||||||
|
import os
|
||||||
|
import chardet
|
||||||
|
|
||||||
|
log = 0 #是否打印日志
|
||||||
|
workPath = os.getcwd() #工作路径
|
||||||
|
|
||||||
|
# 读取配置文件
|
||||||
|
def read_config_file():
|
||||||
|
confList = [] #配置文件路径列表
|
||||||
|
# 遍历目录
|
||||||
|
for root, dirs, files in os.walk(workPath):
|
||||||
|
for file in files:
|
||||||
|
# 检查文件是否以.conf结尾
|
||||||
|
if file.endswith(".conf"):
|
||||||
|
if log:print(os.path.join(root, file))
|
||||||
|
confList.append(os.path.join(root, file))
|
||||||
|
return confList
|
||||||
|
|
||||||
|
# 处理目录结构
|
||||||
|
def config_dir_structure(confPath):
|
||||||
|
# 自动检测文件编码
|
||||||
|
with open(confPath, 'rb') as f:
|
||||||
|
raw_data = f.read()
|
||||||
|
result = chardet.detect(raw_data)
|
||||||
|
encoding = result['encoding']
|
||||||
|
# 读取配置文件
|
||||||
|
with open(confPath, 'r', encoding=encoding) as f:
|
||||||
|
lines = f.readlines()
|
||||||
|
if lines:
|
||||||
|
# 处理目录结构
|
||||||
|
for line in lines:
|
||||||
|
root = {}
|
||||||
|
stack = [(root, -1)] # 栈存储元组 (当前节点, 当前缩进级别)
|
||||||
|
for line in lines:
|
||||||
|
if not line.strip():
|
||||||
|
continue
|
||||||
|
# 计算当前行的缩进级别
|
||||||
|
indent_level = len(line) - len(line.lstrip())
|
||||||
|
# 获取当前目录名称
|
||||||
|
directory_name = line.strip()
|
||||||
|
# 在栈中找到合适的父节点
|
||||||
|
while stack and stack[-1][1] >= indent_level:
|
||||||
|
stack.pop()
|
||||||
|
# 父节点是栈中的最后一个元素
|
||||||
|
parent, _ = stack[-1]
|
||||||
|
# 将当前目录添加到父节点的字典中
|
||||||
|
parent[directory_name] = {}
|
||||||
|
# 将当前目录和其缩进级别推送到栈中
|
||||||
|
stack.append((parent[directory_name], indent_level))
|
||||||
|
return root
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
# 创建目录结构
|
||||||
|
def create_folders(base_path, structure):
|
||||||
|
for folder, substructure in structure.items():
|
||||||
|
current_path = os.path.join(base_path, folder)
|
||||||
|
os.makedirs(current_path, exist_ok=True)
|
||||||
|
if isinstance(substructure, dict):
|
||||||
|
create_folders(current_path, substructure)
|
||||||
|
|
||||||
|
# 配置选择器
|
||||||
|
def run_config_selector(confList):
|
||||||
|
# 根据配置文件列表创建input选择器
|
||||||
|
print("请选择配置文件:")
|
||||||
|
for i, conf in enumerate(confList):
|
||||||
|
print(f"{i+1}. {conf}")
|
||||||
|
choice = int(input("请输入选项:"))
|
||||||
|
if choice in range(1, len(confList)+1):
|
||||||
|
return confList[choice-1]
|
27
main.py
Normal file
27
main.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# -*- coding: UTF-8 -*-
|
||||||
|
|
||||||
|
import os
|
||||||
|
import config as cfg
|
||||||
|
|
||||||
|
def run():
|
||||||
|
# 读取配置文件
|
||||||
|
conFigList = cfg.read_config_file()
|
||||||
|
if not conFigList: print('[没有找到配置文件]')
|
||||||
|
else:
|
||||||
|
# 选择运行配置
|
||||||
|
data = cfg.run_config_selector(conFigList)
|
||||||
|
# 处理目录结构
|
||||||
|
dirDict = cfg.config_dir_structure(data)
|
||||||
|
os.system('cls')
|
||||||
|
if not dirDict:
|
||||||
|
print('[配置文件为空]\n')
|
||||||
|
run()
|
||||||
|
else:
|
||||||
|
# 创建目录
|
||||||
|
base_path = '.'
|
||||||
|
cfg.create_folders(base_path, dirDict)
|
||||||
|
print('[目录创建成功]\n')
|
||||||
|
run()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
run()
|
28
清除图标缓存.bat
Normal file
28
清除图标缓存.bat
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
rem 关闭Windows外壳程序explorer
|
||||||
|
|
||||||
|
taskkill /f /im explorer.exe
|
||||||
|
|
||||||
|
rem 清理系统图标缓存数据库
|
||||||
|
|
||||||
|
attrib -h -s -r "%userprofile%\AppData\Local\IconCache.db"
|
||||||
|
|
||||||
|
del /f "%userprofile%\AppData\Local\IconCache.db"
|
||||||
|
|
||||||
|
attrib /s /d -h -s -r "%userprofile%\AppData\Local\Microsoft\Windows\Explorer\*"
|
||||||
|
|
||||||
|
del /f "%userprofile%\AppData\Local\Microsoft\Windows\Explorer\thumbcache_32.db"
|
||||||
|
del /f "%userprofile%\AppData\Local\Microsoft\Windows\Explorer\thumbcache_96.db"
|
||||||
|
del /f "%userprofile%\AppData\Local\Microsoft\Windows\Explorer\thumbcache_102.db"
|
||||||
|
del /f "%userprofile%\AppData\Local\Microsoft\Windows\Explorer\thumbcache_256.db"
|
||||||
|
del /f "%userprofile%\AppData\Local\Microsoft\Windows\Explorer\thumbcache_1024.db"
|
||||||
|
del /f "%userprofile%\AppData\Local\Microsoft\Windows\Explorer\thumbcache_idx.db"
|
||||||
|
del /f "%userprofile%\AppData\Local\Microsoft\Windows\Explorer\thumbcache_sr.db"
|
||||||
|
|
||||||
|
rem 清理 系统托盘记忆的图标
|
||||||
|
|
||||||
|
echo y|reg delete "HKEY_CLASSES_ROOT\Local Settings\Software\Microsoft\Windows\CurrentVersion\TrayNotify" /v IconStreams
|
||||||
|
echo y|reg delete "HKEY_CLASSES_ROOT\Local Settings\Software\Microsoft\Windows\CurrentVersion\TrayNotify" /v PastIconsStream
|
||||||
|
|
||||||
|
rem 重启Windows外壳程序explorer
|
||||||
|
|
||||||
|
start explorer
|
Loading…
x
Reference in New Issue
Block a user