#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=..\..\..\Downloads\Aha-Soft-Desktop-Halloween-Halloween.ico #AutoIt3Wrapper_Outfile=IFCS x86.exe #AutoIt3Wrapper_Outfile_x64=IFCS x64.exe #AutoIt3Wrapper_Compile_Both=y #AutoIt3Wrapper_UseX64=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include #include #include #include #include #include #include #include #include #include #include HotKeySet("+!d", "FPause") HotKeySet("+x", "Form1Close") ;$WS_EX_TOPMOST, Opt("WinTitleMatchMode", 2) Opt("GUIOnEventMode", 1) Global $Paused, $counter = 0 #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("IFCS Update", 498, 431, 192, 124, -1, $WS_EX_TOPMOST) GUISetBkColor(0xC0C0C0) GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close") $Group1 = GUICtrlCreateGroup("", 8, 40, 481, 201) $Label1 = GUICtrlCreateLabel("Search in:", 24, 56, 92, 17) $Input1 = GUICtrlCreateInput("C:\Users\john\Desktop\MPTEST", 120, 52, 353, 21) $Label2 = GUICtrlCreateLabel("Left:", 24, 184, 47, 17) $Labell = GUICtrlCreateLabel("Top:", 110, 184, 47, 17) $Checkbox2 = GUICtrlCreateCheckbox("Delay", 24, 214, 129, 17) $Input2 = GUICtrlCreateInput("5", 50, 181, 49, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_UPPERCASE)) $Inputl = GUICtrlCreateInput("5", 140, 181, 49, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_UPPERCASE)) $Label3 = GUICtrlCreateLabel("W:", 312, 186, 18, 17) $Input3 = GUICtrlCreateInput("90", 336, 182, 49, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER)) $Label4 = GUICtrlCreateLabel("H:", 400, 186, 15, 17) $Input4 = GUICtrlCreateInput("25", 424, 182, 49, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER)) $Label5 = GUICtrlCreateLabel("Insert image:", 24, 152, 86, 17) $Input5 = GUICtrlCreateInput("C:\Users\john\Desktop\image.png", 120, 150, 353, 21) $Label6 = GUICtrlCreateLabel("File type:", 24, 88, 66, 17) $Input6 = GUICtrlCreateInput(".xls", 120, 88, 49, 21) $Input7 = GUICtrlCreateInput(".xlsx", 192, 88, 49, 21) $Input8 = GUICtrlCreateInput(".csv", 264, 88, 57, 21) $Label8 = GUICtrlCreateLabel("If cell:", 24, 120, 64, 17) $Input9 = GUICtrlCreateInput("J1", 120, 116, 73, 21) $Label9 = GUICtrlCreateLabel("Contains:", 216, 120, 71, 17) $Input10 = GUICtrlCreateInput("File to be changed", 296, 116, 177, 21) $LabelDepth = GUICtrlCreateLabel("Save in:", 160, 216, 71, 17) $radical = GUICtrlCreateLabel("Nr. of chars:", 380, 216, 71, 17) $DirDepth = GUICtrlCreateInput("C:\Users\john\Desktop", 215, 212, 150, 21) $radicalinput = GUICtrlCreateInput("34", 435, 212, 38, 21) GUICtrlCreateGroup("", -99, -99, 1, 1) $Label7 = GUICtrlCreateLabel("Excel file update Update", 112, 8, 257, 33) GUICtrlSetFont(-1, 18, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0x008000) $Group3 = GUICtrlCreateGroup("", 8, 248, 153, 105) $Checkbox1 = GUICtrlCreateCheckbox("Manual confirmation", 24, 272, 129, 17) $Button1 = GUICtrlCreateButton("Start", 32, 308, 105, 25) GUICtrlSetOnEvent(-1, "Button1Click") GUICtrlCreateGroup("", -99, -99, 1, 1) $StatusBar1 = _GUICtrlStatusBar_Create($Form1) $StatusBar1 = _GUICtrlStatusBar_Create($Form1) $Group2 = GUICtrlCreateGroup("Real-Time Tracking", 176, 248, 313, 105) $Tracking = GUICtrlCreateEdit("", 184, 264, 297, 81, BitOR($ES_AUTOVSCROLL, $ES_WANTRETURN)) GUICtrlSetData(-1, "Tracking..." & @CRLF) GUICtrlCreateGroup("", -99, -99, 1, 1) $Label11 = GUICtrlCreateLabel("Shift-Alt-d = Pause / Continue", 22, 368, 300, Default) GUICtrlSetFont(-1, 14, 800, 0, "Comic Sans MS") GUICtrlSetColor(-1, 0x808080) $Label13 = GUICtrlCreateLabel("Shift-x = Exit", 360, 370, 200, Default) GUICtrlSetFont(-1, 14, 800, 0, "Comic Sans MS") GUICtrlSetColor(-1, 0x808080) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 Sleep(100) WEnd Func Button1Click() Local $folder = GUICtrlRead($Input1) $timestamp = TimerInit() RecursiveFileSearch($folder) MsgBox(0, "", (TimerDiff($timestamp) / 1000) & " seconds") ;0.0902s / 2090 files EndFunc ;==>Button1Click Func Form1Close() Exit 0 EndFunc ;==>Form1Close Func RecursiveFileSearch($startDir, $depth = 0) ; Declaring variables Local $xls = GUICtrlRead($Input6) Local $xlsx = GUICtrlRead($Input7) Local $csv = GUICtrlRead($Input8) Local $cell = GUICtrlRead($Input9) Local $text = GUICtrlRead($Input10) Local $picture = GUICtrlRead($Input5) Local $cellimg = GUICtrlRead($Input2) Local $w = GUICtrlRead($Input3) Local $h = GUICtrlRead($Input4) Local $dir = GUICtrlRead($DirDepth) Local $Rad = GUICtrlRead($radicalinput) If $depth = 0 Then Global $RFSstring = "" $search = FileFindFirstFile($startDir & "\*.*") If @error Then Return $gg = 1 While 1 ToolTip('Script is "Running"', 0, 0, "", 1) $next = FileFindNextFile($search) If @error Then ExitLoop ;If folder, recurse If StringInStr(FileGetAttrib($startDir & "\" & $next), "D") Then RecursiveFileSearch($startDir & "\" & $next, $depth + 1) ; Check if file is excel compatible or shortcut ElseIf StringInStr($startDir & "\" & $next, $xls) Or StringInStr($startDir & "\" & $next, $xlsx) Or StringInStr($startDir & "\" & $next, $csv) Or StringInStr($startDir & "\" & $next, ".lnk") Then ;Open the file Local $oExcel = _Excel_Open() Local $sWorkbook = $startDir & "\" & $next ;MsgBox(Default,Default, $startDir & "\" & $next) --for debug Local $oWorkbook = _Excel_BookOpen($oExcel, $sWorkbook) ;If delay checkbox is checked, wait for window activation If GUICtrlRead($Checkbox2) = $GUI_CHECKED Then WinWaitActive("Microsoft Excel") ;Check if file is one of those we want to replace If _Excel_RangeRead($oWorkbook, Default, $cell) = $text Then ;Delete the existing image by sending VBA code to excel VBA editor, i could not find another way Send("!{F11}") Send("^g") WinActivate("Microsoft Visual Basic") Send('ActiveSheet.Shapes.Range(Array("Picture 1")).Delete') WinActivate("Microsoft Visual Basic") Send("{ENTER}") ; In case of an error in VBA editor, send ESC to clode the error Send("{ESC}") Send("{ESC}") WinActivate("Microsoft Visual Basic") ; Close VBA editor window Send("!q") ; Insert the new picture _Excel_PictureAdd($oWorkbook, Default, $picture, 5, 5, $w, $h) ; If we want manual confirmation, in case of an unwanted file, it will write a log file If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then $ret = MsgBox(4, Default, "Is it ok?") If $ret == 6 Then ElseIf $ret == 7 Then FileWriteLine(@DesktopDir & "\RaportIFCSerror.txt", $startDir & "\" & $next) EndIf EndIf ; Because of compatibility mode we can not save the changes to the .xls file so we will save it to anothe location as a new file using _Excel_BookSaveAs() to a .xlsx file If StringRight($next, 4) = ".xls" Then If Not FileExists($dir&"\"& StringMid($startDir, $Rad)) Then DirCreate($dir&"\"& StringMid($startDir, $Rad)) ; Create directory structure to the new location _Excel_BookSaveAs($oWorkbook, $dir & "\" & StringMid($startDir, $Rad) &"\"& StringReplace($next, ".xls", ".xlsx")) EndIf If StringRight($next, 5) = ".xlsx" Then ;MsgBox(Default, Default, $dir & "\" & StringMid($startDir, $Rad) & "\" & $next) --for debug If Not FileExists($dir&"\"& StringMid($startDir, $Rad)) Then DirCreate($dir&"\"& StringMid($startDir, $Rad)) ; Create directory structure to the new location _Excel_BookSaveAs($oWorkbook, $dir & "\" & StringMid($startDir, $Rad) & "\" & $next) EndIf ;If file is a shortcut, copy the file to the new location --not working for some reason If Not StringRight($next, 4) = ".xls" Or Not StringRight($next, 5) = ".xlsx" Then MsgBox(Default, Default, "Copy: " & $startDir & "\" & $next&" To: "& $dir & "\" & StringMid($startDir, $Rad) & "\") FileCopy($startDir & "\" & $next, $dir & "\" & StringMid($startDir, $Rad) & "\") EndIf ; Write log file FileWriteLine(@DesktopDir & "\RaportIFCSprogress.txt", $startDir & "\" & $next) ; Update statusbar with number of processed files _GUICtrlStatusBar_SetText($StatusBar1, "Documente procesate: " & $gg) _GUICtrlEdit_Scroll($Tracking, $SB_SCROLLCARET) GUICtrlSetData($Tracking, $startDir & "\" & $next & @CRLF, 1) $gg = $gg + 1 _Excel_BookClose($oWorkbook, False) EndIf EndIf WEnd _Excel_Close($oExcel, False, True) FileClose($search) If $depth = 0 Then Return StringSplit(StringTrimRight($RFSstring, 1), "*") EndFunc ;==>RecursiveFileSearch Func FPause() $Paused = Not $Paused While $Paused Sleep(100) ToolTip('Script is "Paused"', 0, 0, "", 1) WEnd ToolTip("") EndFunc ;==>FPause