码迷,mamicode.com
首页 > 移动开发 > 详细

%appdata%目录下配置文件修改(bat脚本方式)

时间:2016-05-13 08:44:07      阅读:447      评论:0      收藏:0      [点我收藏+]

标签:

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

%appdata%目录下配置文件修改(bat脚本方式)

标签:

原文地址:http://www.cnblogs.com/sz-leez/p/5485532.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!