Yuk
Advanced Member | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору ' File: ReplaceInFiles.vbs ' Description: Search and replace of text ' in selected files ' Installation: Create a button on a TC bar ' Command: "disk:\path\ReplaceInFiles.vbs" ' Parameters: "%L" (exactly in "") ' Copyright: (c) 2006, Volniy (mod by Yuk) Option Explicit Dim FSO, Find_String, Replace_String, F, Buffer, ListFile, re Const ForReading = 1, ForWriting = 2 Set FSO = CreateObject("Scripting.FileSystemObject") Set re = New RegExp Find_String = InputBox("Enter search string", "Search and Replace") If Len(Find_String) = 0 Then MsgBox "Search string was not set!", vbExclamation, "Search and Replace" WScript.Quit() End If Replace_String = InputBox("Enter replace string", "Search and Replace") Set ListFile = FSO.OpenTextFile(WScript.Arguments(0), 1) Do While Not ListFile.AtEndOfStream Call DoItForThisFile(ListFile.ReadLine) Loop ListFile.Close Set ListFile = Nothing Set F = Nothing Set FSO = Nothing MsgBox "Replace done!", vbInformation, "Search and Replace" WScript.Quit Sub DoItForThisFile(FilePath) Set F = FSO.OpenTextFile(FilePath, ForReading) Buffer = F.ReadAll F.Close re.Pattern = Find_String re.Global = True re.IgnoreCase = True re.MultiLine = True Buffer = re.Replace(CStr(Buffer), Replace_String) FSO.CopyFile FilePath, FilePath & ".bak" Set F = FSO.OpenTextFile(FilePath, ForWriting) F.Write Buffer F.Close End Sub |