本帖最后由 apang 于 2014-5-31 22:29 编辑
回复 8# zhong365
更改第2行变量的值。ini文件中不能包含有\或/字符- @echo off
- set "a=1" & set "b=50" & set "file=a.ini"
- (for /f "delims=" %%a in ('findstr /n .* "%file%"') do (
- for /f "delims=" %%b in ("\%%a") do (
- set "str=%%~nb"
- setlocal enabledelayedexpansion
- if "!str:~,2!%%~xb" == "2:.%a%" (
- echo,!str:~2!.%b%
- ) else (
- if "!str:~,2!%%~xb" == "2:.%b%" (
- echo,!str:~2!.%a%
- ) else echo,!str:*:=!%%~xb
- )
- endlocal
- )
- ))>$
- move $ "%file%"
- pause
复制代码 或者这样试试:- @set @n=0; /* & echo off
- set "a=1" & set "b=50" & set "file=a.ini"
- cscript -nologo -e:jscript "%~0"<"%file%">$ "%a%" "%b%"
- move $ "%file%"
- pause & exit/b & rem */
- var a = WScript.Arguments(0); b = WScript.Arguments(1);
- var txt = WScript.StdIn.ReadAll();
- var re = new RegExp("^(.*\\r?\\n.*\\.)("+a+"|"+b+")(\\s)", "")
- txt = txt.replace(re,
- function (s0,s1,s2,s3) {
- if (s2 == a){return s1+b+s3} else return s1+a+s3
- }
- )
- WScript.StdOut.Write(txt)
复制代码
|