This repository has been archived on 2026-06-20. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
CLEAN_EVERYTHING/clean_logs.bat
2025-01-16 14:15:40 +08:00

57 lines
1.4 KiB
Batchfile
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
@echo off
chcp 65001 >nul
setlocal enabledelayedexpansion
REM 设置目标目录
set TARGET_DIR=D:\BSERP3\IPOS\ERPApiService_task\ERPQMPOS_Log
REM 设置日志文件路径
set LOG_FILE=%~dp0clean_logs_history.log
REM 检查管理员权限
net session >nul 2>&1
if %errorlevel% neq 0 (
echo 请以管理员身份运行此脚本
pause
exit /b 1
)
REM 检查目标目录是否存在
if not exist "%TARGET_DIR%" (
echo 目标目录不存在:%TARGET_DIR%
pause
exit /b 1
)
REM 初始化变量
set TOTAL_SIZE=0
set FILE_COUNT=0
REM 清理.log文件
for /r "%TARGET_DIR%" %%f in (*.log) do (
set /a FILE_COUNT+=1
for %%s in ("%%f") do set /a TOTAL_SIZE+=%%~zs
echo 删除文件:%%f >> "%LOG_FILE%"
del /f /q "%%f"
)
REM 计算总大小(MB
set /a TOTAL_SIZE_MB=%TOTAL_SIZE%/1048576
REM 记录清理结果
echo ========================================== >> "%LOG_FILE%"
echo 清理时间:%date% %time% >> "%LOG_FILE%"
echo 删除文件数:%FILE_COUNT% >> "%LOG_FILE%"
echo 清理总大小:%TOTAL_SIZE_MB% MB >> "%LOG_FILE%"
echo ========================================== >> "%LOG_FILE%"
REM 清理7天前的日志记录
forfiles /p "%~dp0" /m clean_logs_history.log /d -7 /c "cmd /c del @path"
REM 显示结果
echo.
echo 日志清理完成!
echo 删除文件数:%FILE_COUNT%
echo 清理总大小:%TOTAL_SIZE_MB% MB
pause