; Параметр: %L
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
If $CmdLine[0] < 1 Then
MsgBox (0, "", "Недостаточно параметров, должен быть 1.")
Exit
EndIf
Global $aList = _TCHLoadFileList($CmdLine[1])
Global $gReplaces = 0
$hGUI = GUICreate("Поиск и замена", 563, 232, -1, -1)
$edSrc = GUICtrlCreateEdit("", 8, 48, 265, 145)
$edTrg = GUICtrlCreateEdit("", 288, 48, 265, 145)
$btnOK = GUICtrlCreateButton("OK", 400, 200, 75, 25)
$btnCancel = GUICtrlCreateButton("Отмена", 480, 200, 75, 25)
$lblinfo = GUICtrlCreateLabel("", 8, 6, 295, 17)
GUICtrlCreateLabel("Текст для поиска", 8, 30, 94, 17)
GUICtrlCreateLabel("Текст для замены", 288, 30, 98, 17)
$cbCaseSence = GUICtrlCreateCheckbox("Учитывать регистр", 8, 208, 137, 17)
GUISetState(@SW_SHOW)
GUICtrlSetData($lblinfo, "Выделено для замены " & $aList[0] & " файлов.")
If $aList[0] = 0 Then GUICtrlSetState($btnOK, $GUI_DISABLE)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE, $btnCancel
Exit
Case $btnOK
For $i = 1 To $aList[0]
$sSrcText = FileRead($aList[$i])
$sTrgText = StringReplace($sSrcText, GUICtrlRead($edSrc), GUICtrlRead($edTrg), 0, BitAND(GUICtrlRead($cbCaseSence), $GUI_CHECKED))
If @extended Then
$gReplaces += @extended
$hFile = FileOpen($aList[$i], 2)
FileWrite($hFile, $sTrgText)
FileClose($hFile)
EndIf
Next
MsgBox (0, "", "Выполнено " & $gReplaces & " замен.", 0, $hGUI)
Exit
EndSwitch
WEnd
Func _TCHLoadFileList($sFileName)
Local $asList[1] = [0]
Local $hfList = FileOpen($sFileName, 0)
While 1
$sLine = FileReadLine($hfList)
If @error Then Exitloop
ReDim $asList[UBound($asList)+1]
$asList[UBound($asList)-1] = $sLine
Wend
FileClose($hfList)
$asList[0] = UBound($asList)-1
Return $asList
EndFunc
|