Code:
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Compression=4
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
AutoItSetOption("TrayIconHide", 1)
Opt("GUIOnEventMode", 1)
Opt("GUICoordMode", 1)
Opt("GUIResizeMode", 0)
#Include <File.au3>
#Include <Array.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Dim $Folder = @ScriptDir
Dim $reg = "\s\d+\s\-"
Dim $strEmptyChannelName = "Place Holder Channel"
Dim $strCheckFile = "bouquets.tv"
Dim $Form1 = GUICreate("Remove Channels Numbers from Bouquets", 400, 150, 191, 124)
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")
Dim $Label1 = GUICtrlCreateLabel("Bouquets Folder", 16, 10, 150, 17)
Dim $Input1 = GUICtrlCreateInput($Folder, 16, 25, 201, 21)
Dim $Button1 = GUICtrlCreateButton("Browse", 232, 25, 50, 20, $WS_GROUP)
GUICtrlSetOnEvent(-1, "_Browse_folder")
Dim $Label2 = GUICtrlCreateLabel("Dummy Channel Name", 16, 55, 150, 17)
Dim $Input2 = GUICtrlCreateInput($strEmptyChannelName, 16, 70, 201, 21)
Dim $Label3 = GUICtrlCreateLabel("New Dummy Channel Name", 16, 100, 150, 17)
Dim $Input3 = GUICtrlCreateInput($strEmptyChannelName, 16, 115, 201, 21)
Dim $Button2 = GUICtrlCreateButton("GO", 330, 115, 50, 20, $WS_GROUP)
GUICtrlSetOnEvent(-1, "_ButtonGO")
GUISetState(@SW_SHOW)
Dim $iAction = 0
Dim $bCheckPath = False
While 1
Select
Case $iAction = 0
Sleep(50)
Case $iAction = 1
$bCheckPath = _ButtonGO()
If $bCheckPath = true Then
GUICtrlSetState($Button2,$GUI_DISABLE)
_Process(GUICtrlRead($Input1))
$iAction = 0
GUICtrlSetState($Button2,$GUI_Enable)
Else
$iAction = 0
Endif
EndSelect
WEnd
Func _ButtonGO()
If FileExists(GUICtrlRead($Input1) & "\" & $strCheckFile) = 0 then
MsgBox(4096,"","There is no bouquets.tv in this folder",5)
ConsoleWrite("WWWW" & @CRLF)
return(False)
Else
If GUICtrlRead($Input2) = "" then
MsgBox(4096,"","Dummy channel is blank",5)
return(False)
Else
$iAction = 1
return(True)
EndIf
EndIf
EndFunc
func _Browse_folder()
Local $BouquetsFolder = FileSelectFolder("Choose a Bouquets Folder", "")
GUICtrlSetData($Input1, $BouquetsFolder)
EndFunc
Func SpecialEvents()
Select
Case @GUI_CtrlId = $GUI_EVENT_CLOSE
Exit
Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE
Case @GUI_CtrlId = $GUI_EVENT_RESTORE
EndSelect
EndFunc
Func _Process($strFolder)
Local $arrayFiles = _FileListToArray($strFolder,"*.tv")
If IsArray($arrayFiles) = 1 then
ProgressOn("Progress Meter", "Increments every second", "0 percent")
For $i = 1 to $arrayFiles[0]
ProgressSet( $i, $i & " percent")
_editfile($strFolder & "\" & $arrayFiles[$i])
Next
ProgressSet(100 , "Done", "Complete")
sleep(5000)
ProgressOff()
EndIf
EndFunc
Func _Editfile($FileName)
Local $file = FileOpen($filename,0)
Local $input = fileread($file)
FileClose($file)
Local $output = StringRegExpReplace ($input, $reg, "")
If GUICtrlRead($Input2) <> GUICtrlRead($Input3) then
$output = StringReplace($output,GUICtrlRead($Input2),GUICtrlRead($Input3))
endif
$file = FileOpen($filename,2)
FileWrite($file,$output)
Fileclose($file)
EndFunc