const iFile = "D:\VBS\testdata\iFile.txt" const oFile = "D:\VBS\testdata\oFile.txt" const sTxt = "検索文字1■検索文字2■検索文字3 const rTxt = "置換文字1■置換文字2■置換文字3 call rpTxtFile(iFile,oFile,sTxt,rTxt) 'iFileを開きsTxtをrTxtに置換してoFileとして上書き保存 sub rpTxtFile(iFile,oFile,sTxt,rTxt) '引数文字列を配列に変換 dim sArr:sArr = split(sTxt,"■") dim rArr:rArr = split(rTxt,"■") if ubound(sArr) <> ubound(rArr) then errorEnd("引数のサイズが合っていません。") '入力ファイルの存在確認 dim FSO: Set FSO = CreateObject("Scripting.FileSystemObject") if FSO.FileExists(iFile)=False then errorEnd("入力ファイルがありません。") '入力ファイルを開き、変数に格納 Dim inputFile: Set inputFile = FSO.OpenTextFile(iFile, 1, False, 0) Dim sqlText Do Until inputFile.AtEndOfStream sqlText = inputFile.ReadAll Loop inputFile.Close' バッファを Flush してファイルを閉じる dim k for k = 0 to ubound(sArr) sqlText = replace(sqlText,sArr(k),rArr(k)) next '出力ファイルを開き、テキストを書き込み(本当はフォルダの存在チェックをすべし) Dim wMode:wMode = 2 '2:書き込みモード With FSO.OpenTextFile(oFile, wMode, True, 0) .Write sqlText .Close End With end sub sub errorEnd(msg) msgbox msg Wscript.Quit end sub