Re: [請問] 如何用dos指令更改文字檔案內容?

看板EZsoft (小軟體)作者 (美少婦與女兒同學的故事)時間11年前 (2014/12/02 11:27), 11年前編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
※ 引述《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://www.ptt.cc/bbs/EZsoft/M.1417490859.A.2F2.html ※ 編輯: ljuber (123.192.197.47), 12/04/2014 09:29:56
文章代碼(AID): #1KVJ6hBo (EZsoft)
文章代碼(AID): #1KVJ6hBo (EZsoft)