1.假设%appdata%\leez Program目录下有Cache子目录和配置文件Config.ini
内容为:
[Version]
Version=1.0.0.123
[Options]
WindowWidth=1920
WindowHeight=1080
[Login]
CurrentAccount=leez
2.通过bat脚本修改WindowWidth和WindowHeight值,并删除leez Program目录下Cache子目录,其他配置项保持不变
3.bat脚本实现
@echo off
title Config配置修改
:start
echo =======================================================
echo 选择1,1920*1080
echo 选择2,1600*900
echo 选择0,退出
echo =======================================================
set ProgramDir=%appdata%\leez Program
set ConfigFile=Config.ini
set CacheDir=Cache
cd "%ProgramDir%"
set /p choice= 请选择:
::环境切换选择
if "%choice%" equ "" goto start
if "%choice:~0,1%" equ "1" (
::选择1,1920*1080
set Rep_WindowWidth=1920
set Rep_WindowHeight=1080
goto change )
if "%choice:~0,1%" equ "2" (
::选择2,1600*900
set Rep_WindowWidth=1600
set Rep_WindowHeight=900
goto change )
if "%choice:~0,1%" equ "0" (
goto end )
goto start
:change
setlocal enabledelayedexpansion
for /f "tokens=1-2* delims==" %%a in (%ConfigFile%) do (
set "var=%%b"
if not !var!.==. (
if %%a==WindowWidth (echo %%a^=%Rep_WindowWidth%>>%ConfigFile%.bk
) else if %%a==WindowHeight (echo %%a^=%Rep_WindowHeight%>>%ConfigFile%.bk
) else echo %%a^=%%b>>%ConfigFile%.bk
) else echo %%a>>%ConfigFile%.bk
)
::删除缓存数据
if exist "%CacheDir%" (
rmdir /s/q "%CacheDir%"
)
::替换旧配置文件
move "%ConfigFile%.bk" "%ConfigFile%"
echo "配置修改完成"
goto start
:end
exit