▽1
●
oil999 ●500ポイント ベストアンサー |
詳細なコメントをありがとうございます。
修正したVBScriptを以下に回答しますので、お試しください。
Option Explicit Dim sour, dest, buf Dim pat, str sour = "hoge.txt" '読み込むテキストファイル dest = sour & ".txt" '出力テキストファイル" pat = "^TEST:" '行頭パターン str = "TEST:テストです。" '追加文字列 '正規表現パターンの設定 Dim re Set re = new RegExp re.IgnoreCase = True re.Global = True re.pattern = pat Dim fs, fr, fw Set fs = CreateObject("Scripting.FileSystemObject") Set fr = fs.OpenTextFile(sour) Set fw = fs.CreateTextFile(dest) Dim flag flag = True '行追加の有無フラグ Do Until fr.AtEndOfLine buf = fr.ReadLine If (re.Test(buf)) Then flag = False fw.WriteLine(buf) Loop If Flag Then fw.WriteLine(str) Set re = Nothing Set fw = Nothing Set fr = Nothing Set fs = Nothing