Leaderboard
Popular Content
Showing content with the highest reputation on 03/05/2023 in all areas
-
_ChooseFontEx()
dmob reacted to argumentum for a topic
This was born in a help topic but then I thought I'd be a good UDF to have. The difference between _ChooseFont() and this _ChooseFontEx() , is that it adds: The use of keyword "Default", as default value. Hide parts of the font choosing GUI Uses the proper default color if no color is declared (default) I tested this UDF to work with AutoIt from v3.2.12.1 and the current v3.3.16.1, so it should work in every version. This also copied the Dll calls from other UDFs to this one, to give it independence from otherwise needed additional includes. The Example: #include <_ChooseFontEx.au3> #include <Array.au3> ; for the example Example() Func Example() Local $hParent = GUICreate("Test GUI", 300, 300, @DesktopWidth / 3) For $i = 1 To 7 GUICtrlCreateLabel("label " & $i, 10, $i * 25) Next GUISetState() Sleep(1000) ; used "Arial" as it is found from WinXP to Win11 Local $aFont = _ChooseFont("Arial", 8, 0, 0, False, False, False, $hParent) _ArrayDisplay($aFont, "Example original") $aFont = _ChooseFontEx("Arial", 8, Default, Default, Default, Default, Default, $hParent) _ArrayDisplay($aFont, "Example # 1") $aFont = _ChooseFontEx("Arial", 8, Default, 600, Default, Default, Default, $hParent, 63, "Please choose a font:") _ArrayDisplay($aFont, "Example # 2") Sleep(1000) GUIDelete() EndFunc ;==>Example The UDF: ;~ Opt("MustDeclareVars", 1) ;~ #AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include-once ; if you're gonna use it as UDF #include <Misc.au3> ; for _ChooseFont() ;~ Global $__ChooseFontEx_Hook_WH_CBT = 5, $__ChooseFontEx_Hook_hProc = 0, $__ChooseFontEx_Hook_hHook = 0, _ ; move to "Global" to make it 3.2.12.1 compatible ;~ $__ChooseFontEx_Hook_iHideThese = 3, $__ChooseFontEx_Hook_sNewWinTitle = "", $__ChooseFontEx_Hook_wParamKept = 0, _ ;~ $__ChooseFontEx_Default_iHideThese = 3, $__ChooseFontEx_Default_sNewWinTitle = "", $__ChooseFontEx_Default_hWndOwner = 0 ; #FUNCTION# ==================================================================================================================== ; Name...........: _ChooseFontEx ; Description ...: Creates a Font dialog box that enables the user to choose attributes for a logical font. ; Syntax.........: _ChooseFont([$sFontName = "Courier New"[, $iPointSize = 10[, $iColorRef = 0[, $iFontWeight = 0[, $iItalic = False[, $iUnderline = False[, $iStrikethru = False[, $hWndOwner = 0[, $iHideThese = 7[, $sNewWinTitle = ""]]]]]]]]]]) ; Parameters ....: $sFontName - Default font name ; $iPointSize - Pointsize of font ; $iColorRef - COLORREF rgbColors ; $iFontWeight - Font Weight ; $iItalic - Italic ; $iUnderline - Underline ; $iStrikethru - Optional: Strikethru ; $hWndOwnder - Handle to the window that owns the dialog box ; $iHideThese - Bitwise: Default is 3 ( SysLink and Script ) ; 1: hide SysLink ; 2: hide Script ; 4: hide Color ( if 4 and 8 , also the GroupBox "Effects" will be hidden ) ; 8: hide underline & strikeout ; 16: hide "Font style" ; 32: hide "Font size" ; $sNewWinTitle - Change the WinTitle ; Return values .: Success - Array in the following format: ; |[0] - contains the number of elements ; |[1] - attributes = BitOr of italic:2, undeline:4, strikeout:8 ; |[2] - fontname ; |[3] - font size = point size ; |[4] - font weight = = 0-1000 ; |[5] - COLORREF rgbColors ; |[6] - Hex BGR Color ; |[7] - Hex RGB Color ; Failure - -1 ; Author ........: argumentum ; https://www.autoitscript.com/forum/topic/209809-_choosefontex/ ; Modified.......: ; Remarks .......: Default keyword friendly. Dark Mode friendly. ; Related .......: _ChooseFont() ; Link ..........; ; Example .......; Yes ; =============================================================================================================================== Func _ChooseFontEx($sFontName = "Courier New", $iPointSize = 10, $iFontColorRef = Default, $iFontWeight = 0, _ $bItalic = False, $bUnderline = False, $bStrikethru = False, $hWndOwner = Default, $iHideThese = Default, $sNewWinTitle = Default) Local $aRet, $iErr, $iExt, $COLOR_BTNTEXT = 18 If $iPointSize = Default Then $iPointSize = 10 ; Default as a parameter is not in the Misc.au3 UDF. Added here for convenience. If $iFontColorRef = Default Then $iFontColorRef = 0 $aRet = DllCall("user32.dll", "INT", "GetSysColor", "int", $COLOR_BTNTEXT) ; I use a dark theme, so 0x000000 is not my default. If Not @error Then $iFontColorRef = $aRet[0] EndIf If $iFontWeight = Default Then $iFontWeight = 0 If $bItalic = Default Then $bItalic = False If $bUnderline = Default Then $bUnderline = False If $bStrikethru = Default Then $bStrikethru = False If $hWndOwner = Default Then $hWndOwner = _ChooseFontEx_hWndOwner() ; default = 0 ( no parent gui ) If Not IsHWnd($hWndOwner) Then $hWndOwner = 0 If $iHideThese = Default Then $iHideThese = _ChooseFontEx_HideThese() ; default = 3 ( hide SysLink + hide Script ) If $sNewWinTitle = Default Then $sNewWinTitle = _ChooseFontEx_NewWinTitle() ; default = "" ( no change ) __ChooseFontEx_Hook("StartIt", $iHideThese, $sNewWinTitle) ; logic moved to this func to keep hook variables as local $aRet = _ChooseFont($sFontName, $iPointSize, $iFontColorRef, $iFontWeight, $bItalic, $bUnderline, $bStrikethru, $hWndOwner) $iErr = @error $iExt = @extended __ChooseFontEx_Hook("EndIt", "", "") Return SetError($iErr, $iExt, $aRet) EndFunc ;==>_ChooseFontEx #Region helper func to set new defaults ; #FUNCTION# ==================================================================================================================== ; Name...........: _ChooseFontEx_HideThese() ; Description ...: Set a default value / get value / set "ResetDefault" to Reset default value ( saves you from having to know it ) ; =============================================================================================================================== Func _ChooseFontEx_HideThese($iHideThese = Default) ; set a new default / get value Local $iRet = __ChooseFontEx_Hook("HideThese", $iHideThese, "") Return SetError(@error, @extended, $iRet) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _ChooseFontEx_NewWinTitle() ; Description ...: Set a default WinTitle / get value / set "ResetDefault" to Reset default value ( saves you from having to know it ) ; =============================================================================================================================== Func _ChooseFontEx_NewWinTitle($sNewWinTitle = Default) ; Local $sRet = __ChooseFontEx_Hook("NewWinTitle", $sNewWinTitle, "") Return SetError(@error, @extended, $sRet) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _ChooseFontEx_hWndOwner() ; Description ...: Set a default parent GUI / get value / set "ResetDefault" to Reset default value ( saves you from having to know it ) ; =============================================================================================================================== Func _ChooseFontEx_hWndOwner($hWndOwner = Default) Local $hRet = __ChooseFontEx_Hook("hWndOwner", $hWndOwner, "") Return SetError(@error, @extended, $hRet) EndFunc #EndRegion ; #FUNCTION# ==================================================================================================================== ; Name...........: __ChooseFontEx_Hook ; Description ...: Helper function for _ChooseFontEx() ; Remarks .......: For Internal Use Only ; =============================================================================================================================== Func __ChooseFontEx_Hook($nCode, $wParam, $lParam) ; Tested in XP, 10 and 11 Local Static $__ChooseFontEx_Hook_WH_CBT = 5, $__ChooseFontEx_Hook_hProc = 0, $__ChooseFontEx_Hook_hHook = 0, _ ; move to "Global" to make it 3.2.12.1 compatible $__ChooseFontEx_Hook_iHideThese = 3, $__ChooseFontEx_Hook_sNewWinTitle = "", $__ChooseFontEx_Hook_wParamKept = 0, _ $__ChooseFontEx_Default_iHideThese = 3, $__ChooseFontEx_Default_sNewWinTitle = "", $__ChooseFontEx_Default_hWndOwner = 0 Local $aRet Switch $nCode Case "HideThese" If $wParam = "ResetDefault" Then $__ChooseFontEx_Default_iHideThese = 3 If $wParam <> Default Then $__ChooseFontEx_Default_iHideThese = $wParam Return $__ChooseFontEx_Default_iHideThese Case "NewWinTitle" If $wParam = "ResetDefault" Then $__ChooseFontEx_Default_sNewWinTitle = "" If $wParam <> Default Then $__ChooseFontEx_Default_sNewWinTitle = $wParam Return $__ChooseFontEx_Default_sNewWinTitle Case "hWndOwner" If $wParam = "ResetDefault" Then $__ChooseFontEx_Default_hWndOwner = 0 If $wParam <> Default And IsHWnd($wParam) Then $__ChooseFontEx_Default_hWndOwner = $wParam Return SetError(0, IsHWnd($__ChooseFontEx_Default_hWndOwner), $__ChooseFontEx_Default_hWndOwner) Case "StartIt" $__ChooseFontEx_Hook_sNewWinTitle = $lParam If $wParam < 0 Or $wParam > 63 Or $wParam = Default Then $__ChooseFontEx_Hook_iHideThese = 3 Else $__ChooseFontEx_Hook_iHideThese = Int($wParam) EndIf $__ChooseFontEx_Hook_hProc = DllCallbackRegister("__ChooseFontEx_Hook", "int", "int;int;int") Local $hThreadId = DllCall("kernel32.dll", "dword", "GetCurrentThreadId") If Not @error Then $aRet = DllCall("user32.dll", "handle", "SetWindowsHookEx", "int", $__ChooseFontEx_Hook_WH_CBT, _ "ptr", DllCallbackGetPtr($__ChooseFontEx_Hook_hProc), "handle", 0, "dword", $hThreadId[0]) If Not @error Then $__ChooseFontEx_Hook_hHook = $aRet[0] EndIf Return Case "EndIt" DllCall("user32.dll", "bool", "UnhookWindowsHookEx", "handle", $__ChooseFontEx_Hook_hHook) ;If @error Then ConsoleWrite('! @error ' & @ScriptLineNumber & @CRLF) DllCallbackFree($__ChooseFontEx_Hook_hProc) $__ChooseFontEx_Hook_hHook = 0 $__ChooseFontEx_Hook_hProc = 0 Return EndSwitch ; $nCode = 3 ( 1st control created in the canvas is the window, hance "wParamKept = $wParam" ) If $nCode = 3 And $__ChooseFontEx_Hook_wParamKept = 0 Then $__ChooseFontEx_Hook_wParamKept = $wParam If $nCode = 9 And $__ChooseFontEx_Hook_wParamKept = 1 Then $__ChooseFontEx_Hook_wParamKept = 0 If $nCode = 5 And $__ChooseFontEx_Hook_wParamKept = $wParam Then $__ChooseFontEx_Hook_wParamKept = 1 Local $hWnd = HWnd($wParam) If BitAND($__ChooseFontEx_Hook_iHideThese, 1) Then ControlHide($hWnd, "", "SysLink1") ; <A>Show more fonts</A> If BitAND($__ChooseFontEx_Hook_iHideThese, 2) Then ControlHide($hWnd, "", "Static7") ; Script: ControlHide($hWnd, "", "ComboBox5") ; Script comboBox EndIf If BitAND($__ChooseFontEx_Hook_iHideThese, 4) Then ControlHide($hWnd, "", "Static4") ; Color: ControlHide($hWnd, "", "ComboBox4") ; Color comboBox EndIf If BitAND($__ChooseFontEx_Hook_iHideThese, 8) Then ControlHide($hWnd, "", "Button2") ; Strikeout: ControlHide($hWnd, "", "Button3") ; Underline: EndIf If BitAND($__ChooseFontEx_Hook_iHideThese, 16) Then ; Font style: ControlHide($hWnd, "", "Static2") ControlHide($hWnd, "", "ComboBox2") EndIf If BitAND($__ChooseFontEx_Hook_iHideThese, 32) Then ; Size: ControlHide($hWnd, "", "Static3") ControlHide($hWnd, "", "ComboBox3") EndIf If BitAND($__ChooseFontEx_Hook_iHideThese, 4) And BitAND($__ChooseFontEx_Hook_iHideThese, 8) Then ControlHide($hWnd, "", "Button1") ; Effects: If $__ChooseFontEx_Hook_sNewWinTitle <> "" Then WinSetTitle($hWnd, "", $__ChooseFontEx_Hook_sNewWinTitle) EndIf $aRet = DllCall("user32.dll", "lresult", "CallNextHookEx", "handle", $__ChooseFontEx_Hook_hHook, "int", $nCode, "wparam", $wParam, "lparam", $lParam) If Not @error Then Return $aRet[0] Return 0 EndFunc ;==>__ChooseFontEx_Hook #cs #include <Array.au3> ; for the example Example() Func Example() Local $hParent = GUICreate("Test GUI", 300, 300, @DesktopWidth / 3) For $i = 1 To 7 GUICtrlCreateLabel("label " & $i, 10, $i * 25) Next GUISetState() Sleep(1000) ; used "Arial" as it is found from WinXP to Win11 Local $aFont = _ChooseFont("Arial", 8, Default, 0, False, False, False, $hParent) _ArrayDisplay($aFont, "Example original") _ChooseFontEx_NewWinTitle("My default title") $aFont = _ChooseFontEx("Arial", 8, Default, Default, Default, Default, Default, $hParent) _ArrayDisplay($aFont, "Example # 1") $aFont = _ChooseFontEx("Arial", 8, Default, 600, Default, Default, Default, $hParent, 63, "Please choose a font:") _ArrayDisplay($aFont, "Example # 2") Sleep(1000) EndFunc ;==>Example #ce Talking to myself: I don't know if start annoying the MVPs into modifying the default ChooseFont() to include these features in it is well worth it. It should be but I don't wanna push the code uphill ...hmmm. They may just do it if they see this expansion as favorable. At least the default color should be implemented. idk. If you're using this thing, please do leave a like, as to get an idea if is really useful or just not that useful. Thank you.1 point -
ShareX.exe -ColorPicker
argumentum reacted to ioa747 for a topic
ShareX.exe -ColorPicker for those who don't know ! ShareX is a free and open source program - Screen capture, file sharing and productivity tool ColorPicker It is a separate tool of his where you can call it with ShareX.exe -ColorPicker I use it Regularly, so I said to order in AutoIt services if you choose a color by double-clicking in scite on the hex color , you can then use get Get to get it, to see the color, or use Set to set it, change it with <-- button insert color name as comment, at the cursor position ; https://www.autoitscript.com/forum/topic/209749-sharexexe-colorpicker/ ;------------------------------------------------------------------------------ ; Title...........: CollorSX.au3 ; Description.....: ShareX.exe -ColorPicker ;------------------------------------------------------------------------------ #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <WindowsConstants.au3> #include <SendMessage.au3> #include <AutoItConstants.au3> #include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <StringConstants.au3> Global $ClipBack, $ClipData, $hSciTE, $hCtrlHnd, $hShareX, $ShareX_Pos, $iState, $ColorName Global $hGhostGUI, $idButtonGet, $idButtonSet, $idColorName, $idButtonCopyTxt, $ActStatus, $TmpStatus, $HexColor If Not WinExists("[CLASS:SciTEWindow]") Then Exit EndIf ; copy selected text from SciTE $ClipBack = ClipGet() ; backup clip data $hSciTE = WinActivate("[CLASS:SciTEWindow]") $hCtrlHnd = ControlGetFocus($hSciTE) $hCtrlHnd = ControlGetHandle($hSciTE, '', $hCtrlHnd) _SendMessage($hCtrlHnd, $WM_COPY) $ClipData = ClipGet() LoadShareX("C:\Program Files\ShareX\ShareX.exe") $hShareX = WinWait("ShareX - Color picker") WinActivate($hShareX) ControlClick($hShareX, "", "[NAME:btnClipboardColorPicker]") $ColorName = ControlGetText($hShareX, "", "[NAME:lblNameValue]") $ShareX_Pos = WinGetPos($hShareX) ; get the ShareX win color $HexColor = PixelGetColor($ShareX_Pos[0] + 550, $ShareX_Pos[1] + 50) $HexColor = "0x" & Hex($HexColor, 6) ClipPut($ClipBack) ; Restore backup clip data ; Set the ShareX window as being ontop ConsoleWrite("$WinOnTop=" & WinSetOnTop($hShareX, "", $WINDOWS_ONTOP) & @CRLF) $hGhostGUI = GUICreate('GhostGUI', 210, 43, $ShareX_Pos[0] + 475, $ShareX_Pos[1] + 320, $WS_POPUP, $WS_EX_TOOLWINDOW, $hShareX) GUISetBkColor($HexColor) $idColorName = GUICtrlCreateEdit($ColorName, 3, 1, 180, 19, $ES_CENTER) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, 0x272727) $idButtonCopyTxt = GUICtrlCreateButton("<--", 183, 0, 24, 21) $idButtonGet = GUICtrlCreateButton("Get", 3, 23, 100, 20) $idButtonSet = GUICtrlCreateButton("Set", 107, 23, 100, 20) ; Display the GUI. GUISetState(@SW_SHOW, $hGhostGUI) WinActivate($hShareX) ;Yellow 0xFFFF00 ;Gray 0x7E7E7E ;Goldenrod 0xE39024 ;Lawn green 0x75DC19 ;Dark slate gray 0x063549 ;********************************************************************* While WinExists($hShareX) If Not WinExists($hSciTE) Then Exit EndIf ; Retrieve the state of the ShareX window $iState = WinGetState($hShareX) Switch $iState Case 7, 15 $ActStatus = @SW_SHOW Case 5, 23 $ActStatus = @SW_HIDE EndSwitch If $ActStatus <> $TmpStatus Then ;ConsoleWrite("$iState=" & $iState & @CRLF) GUISetState($ActStatus, $hGhostGUI) $TmpStatus = $ActStatus If $ActStatus = @SW_SHOW Then WinActivate($hShareX) $HexColor = "0x" & ControlGetText($hShareX, "", "[NAME:txtHex]") $ColorName = ControlGetText($hShareX, "", "[NAME:lblNameValue]") ConsoleWrite("# " & $HexColor & " ; " & $ColorName & @CRLF) GUICtrlSetData($idColorName, $ColorName) EndIf EndIf If WinActive($hShareX) Then $ShareX_Pos = WinGetPos($hShareX) WinMove($hGhostGUI, "", $ShareX_Pos[0] + 475, $ShareX_Pos[1] + 320) $ColorName = ControlGetText($hShareX, "", "[NAME:lblNameValue]") If $ColorName <> GUICtrlRead($idColorName) Then GUICtrlSetData($idColorName, $ColorName) EndIf EndIf Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idButtonCopyTxt $ClipBack = ClipGet() ; backup clip data ClipPut(";" & GUICtrlRead($idColorName)) WinActivate($hSciTE) _SendMessage($hCtrlHnd, $WM_PASTE) Global $SpaceCnt = 2 StringReplace(ClipGet(), " ", " ", 0, $STR_CASESENSE) If @extended >= 1 Then $SpaceCnt += @extended EndIf Send("+^{LEFT " & $SpaceCnt & "}") ClipPut($ClipBack) ; Restore backup clip data Case $idButtonGet $ClipBack = ClipGet() ; backup clip data _SendMessage($hCtrlHnd, $WM_COPY) ControlClick($hShareX, "", "[NAME:btnClipboardColorPicker]") $HexColor = "0x" & ControlGetText($hShareX, "", "[NAME:txtHex]") $ColorName = ControlGetText($hShareX, "", "[NAME:lblNameValue]") ConsoleWrite("- Get " & $HexColor & " ; " & $ColorName & @CRLF) GUICtrlSetData($idColorName, $ColorName) ClipPut($ClipBack) ; Restore backup clip data Case $idButtonSet $ClipBack = ClipGet() ; backup clip data $HexColor = "0x" & ControlGetText($hShareX, "", "[NAME:txtHex]") $ColorName = ControlGetText($hShareX, "", "[NAME:lblNameValue]") ClipPut($HexColor) WinActivate($hSciTE) _SendMessage($hCtrlHnd, $WM_PASTE) Send("+^{LEFT}") ConsoleWrite("+ Set " & $HexColor & " ; " & $ColorName & @CRLF) GUICtrlSetData($idColorName, $ColorName) ClipPut($ClipBack) ; Restore backup clip data EndSwitch Sleep(10) WEnd ;********************************************************************* Exit ;---------------------------------------------------------------------------------------- Func LoadShareX($sFullPath) If Not WinExists("ShareX - Color picker") Then If Not FileExists($sFullPath) Then $sFullPath = @ScriptDir & "\ShareX.exe" If Not FileExists($sFullPath) Then $sFullPath = @ScriptDir & "\ShareX\ShareX.exe" If Not FileExists($sFullPath) Then Exit MsgBox(262144, StringTrimRight(@ScriptName, 4), "Kindly tell the script where to find ShareX.exe, bye now.", 10) Run('"' & $sFullPath & '" -ColorPicker') EndIf EndFunc ;==>LoadShareX don't forget it's still under development ! Please, leave your comments and experiences here. thank you very much ! PS for those who have a portable version of ShareX , don't forget to properly update line 30 LoadShareX("C:\Program Files\ShareX\ShareX.exe")1 point -
NewFile Script
argumentum reacted to Dan_555 for a topic
Uhm, currently the script can read unlimited extensions (within the ini file limitations ... ). you just have to add some to the ini file, there is no need to change anything in the script. Edit: While looking at the sourcecode i have noticed that i have inserted some code which could bypass the error checking. this is now fixed (see post #1 + 2).1 point -
Looking for a way to reach the deepst folder
ioa747 reacted to mistersquirrle for a topic
I wrote my own little recursive search after testing out @Nines solution on just my C:\ drive. It took around 150s to enumerate all the folders (gets faster running it multiple times, seems like), then around 1.5s to actually search the array (~340,000 folders). My solution obviously has less features available than _FileListToArrayRec, but speeds it up a lot by not having to build an array: #include <File.au3> #include <FileConstants.au3> #include <StringConstants.au3> __cLog('Starting...') Global $gsSearchFolder = 'C:\' Global $hTimer = TimerInit() Global $iMax Global $aList = _FileListToArrayRec($gsSearchFolder, "*", $FLTAR_FOLDERS, $FLTAR_RECUR) If @error Then $iMax = 0 Else $iMax = $aList[0] EndIf __cLog('Total folders: ' & $iMax & ', loaded in: ' & Round(TimerDiff($hTimer), 2) & ' ms') Global $iDeep = 0, $sFolder = '' $hTimer = TimerInit() For $iFolder = 1 To $iMax StringReplace($gsSearchFolder & $aList[$iFolder], "\", "\", 0, $STR_CASESENSE) ; $STR_CASESENSE increases speed If @extended > $iDeep Then $iDeep = @extended $sFolder = $aList[$iFolder] EndIf Next __cLog('Depth: ' & $iDeep & ', processed in: ' & Round(TimerDiff($hTimer), 2) & ' ms') __cLog($gsSearchFolder & $sFolder) Global $iMaxDepth = 0, $iTotalFolders = 0, $iTotalFiles = 0 Global $sDeepestFolder = '' Global $hTimer = TimerInit() RecursiveSearch($gsSearchFolder) __cLog('Depth: ' & $iMaxDepth & ', processed in: ' & Round(TimerDiff($hTimer), 2) & ' ms') __cLog('Total folders searched: ' & $iTotalFolders & ', total files: ' & $iTotalFiles) __cLog($sDeepestFolder) Exit Func RecursiveSearch($sFolder, $iMaxRecursion = -1, $iCurrentRecursion = 0) If $iMaxRecursion >= 0 And $iCurrentRecursion > $iMaxRecursion Then __cLog('Max recursion reached: ' & $iCurrentRecursion & '/' & $iMaxRecursion) Return SetError(1, 0, $iCurrentRecursion - 1) EndIf Local $sFile = '' $sFolder = $sFolder & '\' $sFolder = StringReplace($sFolder, '\\', '\', 0, $STR_CASESENSE) Local $sSearchFolder = $sFolder & '*' Local $hSearch = FileFindFirstFile($sSearchFolder) If $hSearch = -1 Then $hSearch = Null ;~ __cLog('No files: ' & $sSearchFolder) Return SetError(2, 0, $iCurrentRecursion - 1) EndIf While 1 $sFile = FileFindNextFile($hSearch) If @error Then ;~ __cLog('Error: ' & @error) ExitLoop EndIf $iTotalFiles += 1 If @extended = 1 Then $iTotalFolders += 1 StringReplace($sFolder & $sFile & '\', '\', '\', 0, $STR_CASESENSE) If @extended > $iMaxDepth Then $iMaxDepth = @extended $sDeepestFolder = $sFolder & $sFile & '\' __cLog('New max depth: ' & $iMaxDepth & ', ' & $sDeepestFolder) ;~ ElseIf @extended = $iMaxDepth Then ;~ __cLog('Tied for (current) longest: ' & $sFolder & $sFile) EndIf $iCurrentRecursion = RecursiveSearch($sFolder & $sFile, $iMaxRecursion, $iCurrentRecursion + 1) EndIf WEnd FileClose($hSearch) $hSearch = Null Return SetError(0, 0, $iCurrentRecursion - 1) EndFunc ;==>RecursiveSearch Func __cLog($sMsg) ConsoleWrite($sMsg & @CRLF) EndFunc And the output for me: 2023-03-05 10.25.47.087: Starting... 2023-03-05 10.28.02.035: Total folders: 342838, loaded in: 134947.48 ms 2023-03-05 10.28.03.469: Depth: 21, processed in: 1434.45 ms 2023-03-05 10.28.03.470: C:\Users\Raven\AppData\Local\Autodesk\webdeploy\production\b788673c90d05b91de61a3242d6fc03e30a0895b\Neutron\UI\Base\Gestura\Gestura\Wrappers\PPI\ppiapi-cpp\doc\cpp\html\search\ 2023-03-05 10.28.40.066: Depth: 21, processed in: 36596.04 ms 2023-03-05 10.28.40.066: Total folders searched: 342838, total files: 1901158 2023-03-05 10.28.40.066: C:\Users\Raven\AppData\Local\Autodesk\webdeploy\production\b788673c90d05b91de61a3242d6fc03e30a0895b\Neutron\UI\Base\Gestura\Gestura\Wrappers\PPI\ppiapi-cpp\doc\c\html\search\ 135s vs 37s, similar resulting folder, just a bit different because of the scan/sort order, but otherwise same amount of folders processed. If you needed to find all folders that are at the same max depth you'd have to store them in an array or something and reset it each time you found a new max depth.1 point -
Unterminated string maybe longer than 5000 chars
harrykien reacted to mistersquirrle for a topic
Are you sure that Volatile is what you want? https://www.autoitscript.com/autoit3/docs/keywords/Volatile.htm It might be causing some problems itself. As for your string, the variable can hold more than that: https://www.autoitscript.com/autoit3/docs/appendix/LimitsDefaults.htm, up to 2,147,483,647 for max string length, however for a single line in the script, only 4095. Just using an ampersand (&) will not solve the issue, as it's still a single line. You'll need to create a new line with $sVar &= 'More text'. If this is an issue of too long of a string in your script itself, just take some more time to do something like: Local $sLongString $sLongString = 'blah 1' $sLongString &= 'blah 2' $sLongString = $sLongString & 'blah 3' And just make sure that no single line is more than 4095 characters. You also do not have to break the lines cleanly, you can break them where ever, so I'd stay away from trying to get 4095 exactly. Another option is to save/write that long string to a file, and read it from the script: Local $hFile = FileOpen('LongString.txt') Local $sLongString = FileRead($hFile) FileClose($hFile) If you're still having issues then please post a section of the code that you're having an issue with if you can, so we can better understand the issue.1 point -
1 point