🐛 修复迁移旧版数据库失败的BUG

This commit is contained in:
2025-05-26 15:10:12 +08:00
parent cca3dc5d4d
commit c131692b19
15 changed files with 345 additions and 119 deletions
+32
View File
@@ -0,0 +1,32 @@
import os
from zhenxun.services.log import logger
class CToolManager:
@classmethod
def renameFile(cls, currentFilePath: str, newFileName: str) -> bool:
"""重命名文件,如果目标文件名已存在则先删除再重命名
Args:
currentFilePath (str): 当前文件的完整路径
newFileName (str): 重命名后的文件名
Returns:
bool: 重命名成功返回 True,否则返回 False
"""
try:
dirPath = os.path.dirname(currentFilePath)
newFilePath = os.path.join(dirPath, newFileName)
if os.path.exists(newFilePath):
os.remove(newFilePath)
os.rename(currentFilePath, newFilePath)
return True
except Exception as e:
logger.warning(f"文件重命名失败: {e}")
return False
g_pToolManager = CToolManager()