China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-07-31 21:21
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Ask - How to modify the parameter values in an ini file without opening it View 5,023 Replies 11
Original Poster Posted 2006-04-05 12:14 ·  文莱
新手上路
Credits 8
Posts 2
Joined 2006-04-05 12:10
20-year member
UID 53361
Status Offline
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.
Floor 2 Posted 2006-04-05 13:24 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
```
@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.
Floor 3 Posted 2006-04-05 14:17 ·  文莱
新手上路
Credits 8
Posts 2
Joined 2006-04-05 12:10
20-year member
UID 53361
Status Offline
Heheh, thanks, big shot, but I still don't get it. I'll take it back and study it carefully.
Floor 4 Posted 2006-04-05 18:04 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
If there are no objections to using third-party tools, then using tools like Horst's VarSet or inifile is simpler.
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 5 Posted 2006-04-05 19:01 ·  中国 辽宁 朝阳 联通
铂金会员
★★★★
痴迷DOS者
Credits 5,798
Posts 1,924
Joined 2003-06-20 00:00
23-year member
UID 5583
Gender Male
From 金獅電腦軟體工作室
Status Offline
Agree with the statement above.
熟能生巧,巧能生精,一艺不精,终生无成,精亦求精,始有所成,臻于完美,永无止境!
金狮電腦軟體工作室愿竭诚为您服务!
QQ群:8393170(定期清理不发言者)
个人网站:http://www.520269.cn
电子邮件:doujiehui@vip.qq.com
微信公众号: doujiehui
Floor 6 Posted 2006-04-05 20:51 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
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.
Floor 7 Posted 2006-04-06 03:20 ·  中国 山西 运城 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
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:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 8 Posted 2006-04-06 19:09 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
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.
Floor 9 Posted 2006-04-06 21:01 ·  中国 河北 保定 移动
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
Both of you are masters at arguing. My admiration for both of you is also like a continuous torrent of water...
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 10 Posted 2006-04-06 21:13 ·  中国 上海 电信
金牌会员
★★★★
Credits 4,639
Posts 2,239
Joined 2005-01-30 00:00
21-year member
UID 35785
Gender Male
Status Offline
Originally posted by Climbing at 2006-4-6 21:01:
Both of you are masters at arguing. My admiration for both of you is also like a continuous torrent of water...


Hahahahaha……

Although I don't understand anything, Xiao Ke, you are getting cuter and cuter. Come on, let me give you a kiss Hahahahaha……
Floor 11 Posted 2006-04-06 21:55 ·  中国 山西 临汾 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
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:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 12 Posted 2006-04-07 13:59 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
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.
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Forum Jump: