Re: [请问] 如何用dos指令更改文字档案内容?

楼主: ljuber (美少妇与女儿同学的故事)   2014-12-02 11:27:36
※ 引述《ljuber (美少妇与女儿同学的故事)》之铭言:
: 我有个文字档案
: 想把内容里面有DI的字眼 改成BI
: 不知道用dos批次档可否实践这个方式?
: 我尝试用for写不太出来
自己用google找到一个不错的解决方式
分享一下
Create file replace.vbs:
Const ForReading = 1
Const ForWriting = 2
strFileName = Wscript.Arguments(0)
strOldText = Wscript.Arguments(1)
strNewText = Wscript.Arguments(2)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFileName, ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, strOldText, strNewText)
Set objFile = objFSO.OpenTextFile(strFileName, ForWriting)
objFile.Write strNewText 'WriteLine adds extra CR/LF
objFile.Close
To use this revised script (which we’ll call replace.vbs) just type a
command similar to this from the command prompt:
上面的存成replace.vbs
cscript replace.vbs "C:\Scripts\Text.txt" "DI" "BI"

Links booklink

Contact Us: admin [ a t ] ucptt.com