|
hisean
新手上路

积分 8
发帖 2
注册 2006-4-5
状态 离线
|
『楼 主』:
请教--如何不打开一个ini文件并修改其中参数值
使用 LLM 解释/回答一下
有这样一个需求。
想通过命令行方式修改INI文件中某个参数的赋值,但不想通过notepad,edit等进行人为手工查找替换等操作。这个参数在该INI中名字唯一,但行数不是固定。
There is such a requirement. I want to modify the assignment of a certain parameter in the INI file through the command line method, but I don't want to perform manual operations such as manual search and replace through notepad, edit, etc. This parameter is unique in the name in the INI, but the line number is not fixed.
|
|
2006-4-5 12:14 |
|
|
3742668
荣誉版主
      
积分 2013
发帖 718
注册 2006-2-18
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
@echo off
for /f "delims=: tokens=1,2" %%i in ('"findstr /n . 123.txt"') do set %%i=%%j & set col=%%i
for /f "delims=:" %%m in ('"findstr /n /c:"内容" 123.txt"') do set num=%%m
set /a var = num - 1
for /l %%n in (1,1,%var%) do echo %%%%n%% | findstr . >>tmp.txt
echo %%%num%:内容=新内容%% | findstr . >>tmp.txt
set /a var = var + 2
for /l %%e in (%var%,1,%col%) do echo %%%%e%% | findstr . >>tmp.txt
自己看着改改,原理就这些了。
```
@echo off
for /f "delims=: tokens=1,2" %%i in ('"findstr /n . 123.txt"') do set %%i=%%j & set col=%%i
for /f "delims=:" %%m in ('"findstr /n /c:"Content" 123.txt"') do set num=%%m
set /a var = num - 1
for /l %%n in (1,1,%var%) do echo %%%%n%% | findstr . >>tmp.txt
echo %%%num%:Content=new content%% | findstr . >>tmp.txt
set /a var = var + 2
for /l %%e in (%var%,1,%col%) do echo %%%%e%% | findstr . >>tmp.txt
```
Just modify it yourself, that's the principle.
|
|
2006-4-5 13:24 |
|
|
hisean
新手上路

积分 8
发帖 2
注册 2006-4-5
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
嘿嘿,谢谢大侠,不过还没有看懂,拿回去好好研究一下。
Heheh, thanks, big shot, but I still don't get it. I'll take it back and study it carefully.
|
|
2006-4-5 14:17 |
|
|
Climbing
铂金会员
       网络独行侠
积分 6962
发帖 2753
注册 2003-4-16 来自 河北保定
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
如果不反对使用第三方工具,那么使用Horst的VarSet或者inifile这一类的工具更简单。
If there are no objections to using third-party tools, then using tools like Horst's VarSet or inifile is simpler.
|

偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
|
|
2006-4-5 18:04 |
|
|
Kinglion
铂金会员
       痴迷DOS者
积分 5798
发帖 1924
注册 2003-6-20 来自 金獅電腦軟體工作室
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
同意楼上的说法。
Agree with the statement above.
|

熟能生巧,巧能生精,一艺不精,终生无成,精亦求精,始有所成,臻于完美,永无止境!
金狮電腦軟體工作室愿竭诚为您服务!
QQ群:8393170(定期清理不发言者)
个人网站:http://www.520269.cn
电子邮件:doujiehui@vip.qq.com
微信公众号: doujiehui
|
|
2006-4-5 19:01 |
|
|
3742668
荣誉版主
      
积分 2013
发帖 718
注册 2006-2-18
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
等。。等,我要抬个......杠。
如果用第三方工具的话比如用vbs了,灵活简便,follow me...
if WScript.Arguments.Count <> 0 Then
myFile = Wscript.Arguments(0)
else
SET oFO = CreateObject("SAFRCFileDlg.FileOpen")
oFO.OpenFileOpenDlg
myFile = oFO.FileName
end if
strOld = InputBox("输入要被替换的文字:")
if Len(Trim(strOld)) = 0 then Wscript.Quit
strNew = InputBox("输入被替换后的文字:")
if Len(Trim(strNew)) = 0 then Wscript.Quit
with CreateObject("Scripting.FileSystemObject")
SET FILE = .OpenTextFile(myFile,1,true)
fStr = FILE.Readall
FILE.Close
fStr = Replace(fStr,strOld,strNew,1,1)
SET FILE = .OpenTextFile(myFile,2,true)
FILE.Write fStr
end with
保存为 修改ini文件.vbs ,然后把要修改的文件直接拖放到它上面,然后按照提示来就行了,如果直接双击会打开对话框让你选择要修改的文件。
默认只替换一次,如果想替换多次的话可以自行修改倒数第四行的最后一个1为其他的数字。
似乎跑题了,这里是DOS论坛,我的同志们。
Wait... wait, I want to raise a... quibble.
If using a third-party tool, like using VBS, it's flexible and simple, follow me...
if WScript.Arguments.Count <> 0 Then
myFile = Wscript.Arguments(0)
else
SET oFO = CreateObject("SAFRCFileDlg.FileOpen")
oFO.OpenFileOpenDlg
myFile = oFO.FileName
end if
strOld = InputBox("Enter the text to be replaced:")
if Len(Trim(strOld)) = 0 then Wscript.Quit
strNew = InputBox("Enter the replaced text:")
if Len(Trim(strNew)) = 0 then Wscript.Quit
with CreateObject("Scripting.FileSystemObject")
SET FILE = .OpenTextFile(myFile,1,true)
fStr = FILE.Readall
FILE.Close
fStr = Replace(fStr,strOld,strNew,1,1)
SET FILE = .OpenTextFile(myFile,2,true)
FILE.Write fStr
end with
Save as "Modify ini file.vbs", then directly drag the file to be modified onto it, and then follow the prompts. If you double-click it directly, a dialog box will open for you to select the file to be modified.
By default, it only replaces once. If you want to replace multiple times, you can modify the last 1 in the fourth last line to another number by yourself.
It seems off-topic, this is the DOS forum, my comrades.
|
|
2006-4-5 20:51 |
|
|
willsort
元老会员
         Batchinger
积分 4432
发帖 1512
注册 2002-10-18
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
Re 3742668:
杠需要两人抬,我也帮下忙吧
首先,vbs可以由Windows自带的cscript提供支持,所以不能算“第三方”;其次,vbs是脚本语言,而“工具”只能是其支持程序,比如cscript;再次,修改ini并非字符串替换,因为通常我们是根据ini中的变量名而非变量值或者变量名+变量值来修改变量;最后,若要不跑DOS论坛的题,那么你的CMD脚本也该挂冠归隐了。
另外,在没使用inifile和VarSet之前,在DOS下也曾编过类似的批处理代码,可惜现在找不到了,重写编写则没有太强的目的性。
Re 3742668:
The burden needs two people to carry, I'll also help a bit ;)
First, vbs can be supported by the cscript that comes with Windows, so it can't be regarded as "third-party"; second, vbs is a scripting language, and "tools" can only be its supporting programs, such as cscript; third, modifying ini is not string replacement, because usually we modify variables according to the variable names in ini rather than variable values or variable names + variable values; finally, if you don't want to solve the problems of the DOS forum, then your CMD script should also retire.
In addition, before using inifile and VarSet, I also compiled similar batch code under DOS, but unfortunately I can't find it now, and rewriting has no strong purpose.
|

※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得! |
|
2006-4-6 03:20 |
|
|
3742668
荣誉版主
      
积分 2013
发帖 718
注册 2006-2-18
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
Re willsort:
既然是抬杠那我还是要继续。
首先,有鉴于本人在6楼可耻地出现的笔误,给willsort兄造成了错觉,认为我把vbs当作第三方工具了,其实我的原话应该是“如果用第三方工具的话不如用vbs了,灵活简便,follow me...”,请注意偏移量为10处的字为“不”,所以,willsort兄的第一杠无效。
其次,由于没有领会到楼主提问的精神,造成脚本目的性的错误,但是从另一个角度来看,只需要对我的俩脚本稍加改造就可实现要求,给予了楼主自己编写的机会。当然,如果有人说我的脚本可移植性强我也没有意见。
最后,挂冠归隐这个词让我觉得似乎不是在抬杠,再说了,CMD和DOS看起来也算是差不多,且是一母所生,算做是DOS也不是很牵强吧。
Re willsort:
Since it's a quibble, I still need to continue.
First of all, in view of my shameful typo in the 6th floor, it caused Brother willsort to have a misunderstanding that I regarded VBS as a third-party tool. In fact, my original words should be "If using a third-party tool, it's better to use VBS, flexible and simple, follow me...", please note that the word at the 10th offset is "not", so Brother willsort's first quibble is invalid.
Second, due to not understanding the spirit of the owner's question, it caused a wrong purpose of the script. But from another perspective, only a little modification of my two scripts can achieve the requirement, giving the owner the opportunity to write by himself. Of course, if someone says that my script has strong portability, I have no objection.
Finally, the phrase "hanging up the official hat and retiring" makes me feel that it doesn't seem to be a quibble. Besides, CMD and DOS seem to be similar, and they are of the same origin, so it's not too far-fetched to count as DOS.
|
|
2006-4-6 19:09 |
|
|
Climbing
铂金会员
       网络独行侠
积分 6962
发帖 2753
注册 2003-4-16 来自 河北保定
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
两位都是抬杠的高手,我对两位的景仰之情同样都如滔滔江水,连绵不绝...
Both of you are masters at arguing. My admiration for both of you is also like a continuous torrent of water...
|

偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
|
|
2006-4-6 21:01 |
|
|
DOSforever
金牌会员
     
积分 4639
发帖 2239
注册 2005-1-30
状态 离线
|
|
2006-4-6 21:13 |
|
|
willsort
元老会员
         Batchinger
积分 4432
发帖 1512
注册 2002-10-18
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
Re All:
抬杠还是适可而止吧,正所谓“小抬怡情,大抬伤身”。因此,关于CMD与DOS的错综纠缠不再详述。
需要提请各位注意的是,在此 ”DOS疑難解答 & 問題討論 (解答室)” 中,近期内涌现出大量讨论 WiindowsNT 命令脚本的主题帖,这固然可以长足促进 Windows NT 命令脚本的交流和发展,但由于类似园艺学中的顶端优势原理,其他类型的讨论主题必不可免的受到抑制性影响。从长远和大局来看,这对 CNDOS 论坛的发展是不利的。因此,建议更多用户,积极发表和回复其他类型的主题,全面促进论坛建设和发展。
谢谢合作!
Re All:
Let's stop the fruitless arguments. As the saying goes, "A little argument is enjoyable, but too much is harmful." Therefore, we won't go into the complex relationship between CMD and DOS in detail.
It should be brought to everyone's attention that recently, there have been a large number of threads discussing Windows NT command scripts in the "DOS Difficulties & Problem Discussions (Q&A Room)" here. While this can certainly greatly promote the communication and development of Windows NT command scripts, due to the principle of apical dominance in horticulture, other types of discussion topics are inevitably affected in a restrictive way. In the long run and from a overall perspective, this is not beneficial to the development of the CNDOS forum. Therefore, it is suggested that more users actively post and reply to other types of topics to comprehensively promote the construction and development of the forum.
Thank you for your cooperation!
|

※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得! |
|
2006-4-6 21:55 |
|
|
Climbing
铂金会员
       网络独行侠
积分 6962
发帖 2753
注册 2003-4-16 来自 河北保定
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
到现在,纯DOS实在没有什么太多的新鲜话题可资讨论,你说呢,wil兄?
到目前为止,一涉及到纯DOS,基本上就是USB设备如何驱动?一个游戏该如何能玩?内存该怎么优化?要么就是串口读写之类的问题了。基本上,要么是无法解决,要么就是讨论了太多。
不谈cmd与DOS的区别有多大,毕竟cmd还是属于DOS范畴,别攻击我,我是这么认为的。我还是原来的论调,以实用为主,不要形而上学。
Up to now, there is really not too many new topics to discuss about pure DOS, what do you think, Brother wil?
So far, as soon as it comes to pure DOS, basically it's about how to drive USB devices? How to play a game? How to optimize memory? Or problems like serial port reading and writing. Basically, either it can't be solved, or it has been discussed too much.
Don't talk about how different cmd is from DOS. After all, cmd still belongs to the DOS category, don't attack me, this is what I think. I still have my original opinion, focus on practicality, not metaphysics.
|

偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
|
|
2006-4-7 13:59 |
|