作者ljuber (美少妇与女儿同学的故事)
看板EZsoft
标题Re: [请问] 如何用dos指令更改文字档案内容?
时间Tue Dec 2 11:27:36 2014
※ 引述《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"
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 123.192.197.47
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/EZsoft/M.1417490859.A.2F2.html
※ 编辑: ljuber (123.192.197.47), 12/04/2014 09:29:56