bat 删除 EA 日志文件后更新claude需添加定时或开机任务
·
@echo off
setlocal enabledelayedexpansion
:: ==============================================
:: EA Log Cleaner v2.1
:: Cleans Enterprise Architect log directory
:: Usage: %~nx0 [/i] [/log <path>] [/h|/?]
:: /i Interactive mode (confirm + pause)
:: /log Write operation log to file
:: /h, /? Show help
:: (default) Show progress, no confirm
:: ==============================================
set "EA_INSTALL_PATH="
set "LOG_DIR_NAME=log"
set "INTERACTIVE=0"
set "LOG_FILE="
:: ==============================================
:: Main
:: ==============================================
:main
:parse_args
if "%~1"=="" goto :parse_done
if /i "%~1"=="/h" call :show_usage & exit /b 0
if /i "%~1"=="/?" call :show_usage & exit /b 0
if /i "%~1"=="/i" (
set "INTERACTIVE=1"
shift
goto :parse_args
)
if /i "%~1"=="/log" (
if "%~2"=="" (
echo [ERROR] /log requires a file path
exit /b 1
)
set "LOG_FILE=%~2"
shift
shift
goto :parse_args
)
echo [ERROR] Unknown argument: %~1
echo Use /h for help
exit /b 1
:parse_done
call :detect_ea_path
if errorlevel 1 exit /b !errorlevel!
call :clean_log_dir
if errorlevel 1 exit /b !errorlevel!
call :update_claude
call :echo_msg
call :echo_msg ==============================================
call :echo_msg Done!
call :echo_msg ==============================================
call :echo_msg
if %INTERACTIVE%==1 (
echo Press any key to exit...
pause >nul
)
call :log_msg "Program exited normally"
endlocal
goto :eof
:: ======================================================================
:: Sub: output message (always shown)
:: ======================================================================
:echo_msg
echo(%*
exit /b
:: ======================================================================
:: Sub: write to log file
:: ======================================================================
:log_msg
if not defined LOG_FILE exit /b
>>"%LOG_FILE%" echo [%date:~0,10% %time:~0,8%] %*
exit /b
:: ======================================================================
:: Sub: show usage
:: ======================================================================
:show_usage
echo Usage: %~nx0 [/i] [/log ^<path^>] [/h ^| /?]
echo.
echo /i Interactive mode (add confirmation prompt + pause)
echo /log FILE Write operation log to FILE
echo( /h, /? Show this help
echo.
echo Description:
echo Auto-detect EA install path and clean its log folder.
echo Searches registry then default install paths.
echo.
echo Search order:
echo 1. HKLM\SOFTWARE\WOW6432Node\Sparx Systems\EA
echo 2. HKCU\Software\Sparx Systems\EA400\EA
echo 3. HKCU\Software\Sparx Systems\EA
echo 4. HKLM\SOFTWARE\Sparx Systems\EA
echo 5. Default path (C:/D:/E: Program Files)
exit /b 0
:: ======================================================================
:: Sub: detect EA install path
:: ======================================================================
:detect_ea_path
call :echo_msg
call :echo_msg ==============================================
call :echo_msg Detecting EA install path...
call :echo_msg ==============================================
call :log_msg "Start detecting EA install path"
:: Method 1: HKLM\WOW6432Node
for /f "skip=2 tokens=2*" %%a in (
'reg query "HKLM\SOFTWARE\WOW6432Node\Sparx Systems\EA" /v "InstallPath" 2^>nul'
) do (
set "EA_INSTALL_PATH=%%b"
call :log_msg "Found via HKLM\WOW6432Node: !EA_INSTALL_PATH!"
)
:: Method 2: HKCU user registry (EA400)
if not defined EA_INSTALL_PATH (
for /f "skip=2 tokens=2*" %%a in (
'reg query "HKCU\Software\Sparx Systems\EA400\EA" /v "Install Path" 2^>nul'
) do (
set "EA_INSTALL_PATH=%%b"
call :log_msg "Found via HKCU\EA400: !EA_INSTALL_PATH!"
)
)
:: Method 3: HKCU user registry (EA)
if not defined EA_INSTALL_PATH (
for /f "skip=2 tokens=2*" %%a in (
'reg query "HKCU\Software\Sparx Systems\EA" /v "InstallPath" 2^>nul'
) do (
set "EA_INSTALL_PATH=%%b"
call :log_msg "Found via HKCU\EA: !EA_INSTALL_PATH!"
)
)
:: Method 4: HKLM 32-bit registry
if not defined EA_INSTALL_PATH (
for /f "skip=2 tokens=2*" %%a in (
'reg query "HKLM\SOFTWARE\Sparx Systems\EA" /v "InstallPath" 2^>nul'
) do (
set "EA_INSTALL_PATH=%%b"
call :log_msg "Found via HKLM: !EA_INSTALL_PATH!"
)
)
:: Method 5: Default install paths (multi-drive)
if not defined EA_INSTALL_PATH (
for %%d in (C D E) do (
if not defined EA_INSTALL_PATH (
if exist "%%d:\Program Files\Sparx Systems\EA\EA.exe" (
set "EA_INSTALL_PATH=%%d:\Program Files\Sparx Systems\EA"
call :log_msg "Found via default path (%%d:)"
) else if exist "%%d:\Program Files (x86)\Sparx Systems\EA\EA.exe" (
set "EA_INSTALL_PATH=%%d:\Program Files (x86)\Sparx Systems\EA"
call :log_msg "Found via default path x86 (%%d:)"
)
)
)
)
:: Not found
if not defined EA_INSTALL_PATH (
echo.
echo [ERROR] Cannot find EA install path
echo Please verify EA is installed
echo.
call :log_msg "Error: EA install path not found"
if %INTERACTIVE%==1 pause
exit /b 1
)
call :echo_msg [OK] EA install path: %EA_INSTALL_PATH%
call :log_msg "EA install path: %EA_INSTALL_PATH%"
exit /b 0
:: ======================================================================
:: Sub: clean log directory
:: ======================================================================
:clean_log_dir
set "logdir=%EA_INSTALL_PATH%\%LOG_DIR_NAME%"
if not exist "%logdir%\" (
call :echo_msg [INFO] Log directory not found: %logdir%
call :log_msg "Log directory not found, nothing to clean"
exit /b 0
)
:: Interactive mode: confirm prompt
if %INTERACTIVE%==1 (
echo.
echo ==============================================
echo About to clean the following directory:
echo %logdir%
echo ==============================================
echo This will delete ALL files and subdirectories!
echo.
set "confirm="
set /p "confirm=Continue? (Y/N): "
if /i not "!confirm!"=="Y" (
echo Cancelled
call :log_msg "User cancelled"
exit /b 0
)
)
call :echo_msg
call :echo_msg [PROCESS] Cleaning: %logdir%
call :log_msg "Start cleaning: %logdir%"
:: Count items
set "total_items=0"
for /f %%a in ('dir "%logdir%" /a /s 2^>nul ^| %SystemRoot%\System32\find.exe /c /v ""') do set "total_items=%%a"
if %INTERACTIVE%==1 if not "%total_items%"=="0" (
echo ~%total_items% items ^(files + subdirs^)
)
:: Delete files (force, including read-only and extensionless)
del /F /Q "%logdir%\*" 2>nul
:: Delete subdirectories
for /d %%d in ("%logdir%\*") do rd /Q /S "%%d" 2>nul
:: Verify result
set "remaining=0"
for /f %%a in ('dir "%logdir%" /a /b 2^>nul ^| %SystemRoot%\System32\find.exe /c /v ""') do set "remaining=%%a"
if "%remaining%"=="0" (
call :echo_msg [OK] Directory cleaned successfully
call :log_msg "Log directory cleaned"
) else (
call :echo_msg [WARN] %remaining% items could not be removed
call :log_msg "Warning: %remaining% items remaining after cleanup"
)
exit /b 0
:: ======================================================================
:: Sub: check and update Claude Code if installed
:: ======================================================================
:update_claude
call :echo_msg
call :echo_msg ==============================================
call :echo_msg Checking Claude Code...
call :echo_msg ==============================================
call :log_msg "Start checking Claude Code"
:: Check if claude is available
call where claude >nul 2>&1
if errorlevel 1 (
call :echo_msg [INFO] Claude Code not found, skipping
call :log_msg "Claude Code not found in PATH"
exit /b 0
)
:: Get current version
for /f "tokens=*" %%v in ('claude --version 2^>^&1') do (
call :echo_msg [INFO] Current version: %%v
call :log_msg "Claude Code version: %%v"
)
call :echo_msg [PROCESS] Updating Claude Code...
call :log_msg "Updating Claude Code..."
:: Try claude update command
call claude update 2>&1
if errorlevel 1 (
call :echo_msg [INFO] Trying npm update...
call :log_msg "claude update failed, trying npm"
call npm update -g @anthropic-ai/claude-code 2>&1
if errorlevel 1 (
call :echo_msg [WARN] Claude Code update failed
call :log_msg "Claude Code update failed"
exit /b 0
)
)
call :echo_msg [OK] Claude Code update completed
call :log_msg "Claude Code update completed"
exit /b 0
更多推荐



所有评论(0)