#include #include #include #include ;~ HotKeySet("{ESC}", "HotKeyPressed") ;~ $path=Inputbox("Path to TMX","Enter path:") ;~ _ArrayDisplay($PathsArray) $Form1 = GUICreate("Searching\Replacing SKUs", 510, 250, 256, 115,-1,BitOR($WS_EX_TOPMOST,$WS_EX_ACCEPTFILES)) ;$MergeInputBrowse = GUICtrlCreateButton("Browse", 15, 20, 40, 20) $MergeInputPath = GUICtrlCreateInput('Paste path to xls files or click on "Browse..." to find it', 60, 20, 360, 20) GUICtrlSetState($MergeInputPath, $GUI_DROPACCEPTED) $MergeInputBrowsetxlf = GUICtrlCreateButton("Browse", 15, 60, 40, 20) $MergeInputPathTxlf = GUICtrlCreateInput('Paste path to TXLF files or click on "Browse..." to find it', 60, 60, 360, 20) GUICtrlSetState($MergeInputPathTxlf, $GUI_DROPACCEPTED) $Merge = GUICtrlCreateButton("Start!", 430, 20, 60, 20) $MergeProgress = GUICtrlCreateProgress(15,140, 480, 20) $MergeNotification = GUICtrlCreateInput("Ready to serve, my lord.", 15, 110, 480, 20,$ES_READONLY) $MergeProgress2 = GUICtrlCreateProgress(15,210, 480, 20) $MergeNotification2 = GUICtrlCreateInput("Ready to serve, my lord.", 15, 180, 480, 20,$ES_READONLY) GUICtrlCreateTabItem(""); The end of the tabs, this is needed to separate the last tab from other common elements of the GUI. GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Select Case $nMsg = $MergeInputPath; updates the variable with the path entered in this, by pasting or by using the Browse. $inputFile = GUICtrlRead($MergeInputPath) EndSelect $nMsgtxlf = GUIGetMsg() Select Case $nMsgtxlf = $MergeInputBrowsetxlf $WorkingPath = FileSelectFolder("Select folder","") GUICtrlSetData($MergeInputPathTxlf,$WorkingPath) Case $nMsgtxlf = $MergeInputPathTxlf; updates the variable with the path entered in this, by pasting or by using the Browse. $WorkingPath = GUICtrlRead($MergeInputPathTxlf) Case $nMsgtxlf = $Merge FileChangeDir($WorkingPath) $PathsArraytxlf=_FileListToArrayRec($WorkingPath,"*.txlf",1,1) For $i = 1 to Ubound($PathsArraytxlf)-1 GUICtrlSetData($MergeNotification, "Working on file " & $i & "/" & UBound($PathsArraytxlf)-1 & " : " & $PathsArraytxlf[$i]) GUICtrlSetData($MergeProgress,($i)/(UBound($PathsArraytxlf)-1)*100) Replacer($PathsArraytxlf[$i]) _ReduceMemory() Next MsgBox(0,"","Finished",0,$Form1) Case $nMsgtxlf = $GUI_EVENT_CLOSE Exit Case $nMsgtxlf = $GUI_EVENT_DROPPED ; If the value of @GUI_DropId is $idLabel, then set the label of the dragged file. If @GUI_DropId = $MergeInputPathTxlf Then GUICtrlSetData($MergeInputPathTxlf, @GUI_DragFile) $WorkingPath = GUICtrlRead($MergeInputPathTxlf) EndIf EndSelect WEnd Func Replacer($nMsgtxlf); This one opens files in the path, one by one and makes the replacements. ;Reading TXLF files $iH = FileOpen(@WorkingDir&"\"&$nMsgtxlf,16384) $inContent = FileRead($iH) FileClose($iH) $outContent = StringregexpReplace($inContent,"","") ;$segArray = StringRegExp($outContent,".*?",3); the file is divided into segments. ;IF @error Then MsgBox(0,"","something is wrong"&@CRLF&$segArray) $file=0 ;$errormessage="" ;For $seg In $segArray $file = $file + 1 ;$new=$seg $targetArray=StringRegExp($outContent,"(.*?)",2); each segment is divided into targets (in case there are revisions) If not @error Then; We create an if condition to exclude those TXMLs without targets on it. ;Reading TXT file $iHTXT = FileOpen($inputFile,16384) $inContentTXT = FileRead($iHTXT) FileClose($iHTXT) $findArray = StringRegExp($inContentTXT,'(\"skuId\":\".*?\")(\t)("skuId\":\".*?\")',3) $findkey = $1 $replaceKey = $3 #Region Replacements in TXLF $targetold=$targetArray[1]; and we only use the first target in the file to do the replacements. $targetnew=$targetold $targetnew=StringRegExpReplace($targetnew,"$1","$3") ;$utSplitFull=StringRegExpReplace($targetnew,'(?s)]*>.*?','{ut}'); we then split the selected target by tags ;$utSplitArray=StringSplit($utSplitFull,'{ut}',1) ; in case there are any. We do this because we are replacing doublequotes and we do not want to corrupt ; doublequotes inside tags. ;If $utSplitArray[0]>1 Then ;For $ut=1 to $utSplitArray[0] ;$oldutSplit=$utSplitArray[$ut] ;If $oldutSplit="" Then ContinueLoop ;$newutSplit=$oldutSplit ;$newutSplit=StringRegExpReplace($newutSplit,"\x{0022}","&quot;") ;$targetnew=StringReplace($targetnew,$oldutSplit,$newutSplit,1,1) ;Next ;Else ;$targetnew=StringRegExpReplace($targetnew,"\x{0022}","&quot;") ;EndIf ;ConsoleWrite("New: "&$new&@CRLF&"TargetOld: "&$targetold&@CRLF&"TargetNew: "&$targetnew&@CRLF) ;$new = StringReplace($new,$targetold&"",$targetnew&"",1,1) EndIf $files = UBound($outContent) GUICtrlSetData($MergeNotification2, "Working on segment " & $file & "/" & UBound($outContent) & " : " & $outContent) GUICtrlSetData($MergeProgress2,($file)/(UBound($outContent))*100) ;$outContent = StringReplace($outContent,$seg,$new,1,1) ;Next $oH = FileOpen(@WorkingDir&"\"&$nMsgtxlf,256 + 2) FileWrite($oH,$outContent) FileClose($oH) ;Return $errormessage; After doing all the action it returns the value of the $errormessage variable. EndFunc Func _ReduceMemory($i_PID = -1); function to reduce the RAM memory used by processes called from the script. If $i_PID <> -1 Then Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $i_PID) $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0]) DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0]) Else $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1) EndIf Return $ai_Return[0] EndFunc ;==>_ReduceMemory