Seminko Posted August 30, 2014 Share Posted August 30, 2014 (edited) Hey fellas, I am trying to create a script that would first off prompt you to select a folder which is put into an INI file. Then a fuction checks for the latest file in specified folder and checks if the first three letters of such file are "Log". If such file is not found a MsgBox should appear where when pressed NO it would prompt you to reselect the folder and do the file name check again. And this is where the script fail. In the reselection. The script works in these scenarios: 1) If the folder has already been specified in the INI file, the script correctly goes right into the main loop - WORKS 2) If there is no folder specified in the INI file, it specifies it and goes into the main loop - WORKS But if, you select a folder and FileSelect function does not find any "Log" file and you press NO in the msgbox to reselect the correct folder with a "Log" file inside it will just continuously fire the msgbox over and over again. Anybody? expandcollapse popup#include <FileCountOccurrences.au3> #include <String.au3> #include <Array.au3> #include <Date.au3> #include <FileConstants.au3> #include <File.au3> ;#RequireAdmin HotKeySet("{F8}", "Terminate") Call("FolderCheck") Call("FileSelect") While 1 Local $WinCount = _FileCountOccurrences($sFolder & $newfile, "Victory") If $WinCount >= 1 Then Call("ShutdownPC") EndIf Sleep(2000) WEnd Func FolderCheck() Global $sFolder = IniRead("config.ini", "Path", "Log", "") If $sFolder = "" Then Call("FolderSelect") Global $sFolder = IniRead("config.ini", "Path", "Log", "") EndIf EndFunc Func FileSelect() $last = 0 $aFiles = _FileListToArray($sFolder , "*" , 1) for $i = 1 to $aFiles[0] $time = filegettime($sFolder & "\" & $aFiles[$i] , 0 , 1) If $time > $last Then Global $newfile = $aFiles[$I] $last = $time EndIf next Global $NewFileName = StringLeft($newfile, 3) If $NewFileName <> "Log" Then $MyBox = MsgBox(4, "Cannot find a Log file", "There is no Log file in the folder selected. Is this the correct folder?" & @CRLF & @CRLF & "Press YES, If you are sure the folder is correct to Exit the script. Manually create a log." & @CRLF & @CRLF & "Press NO to reselect the folder.") If $MyBox = 6 Then Exit ElseIf $MyBox = 7 Then Call("FolderSelect") Call("FileSelect") EndIf EndIf EndFunc Func FolderSelect() Local Const $sMessage = "Select Log folder." $sFileSelectFolder = FileSelectFolder($sMessage, "") If @error Then MsgBox(1, "", "No folder was selected.") Else IniWrite("config.ini", "Path", "Log", $sFileSelectFolder & "\") EndIf EndFunc Func ShutdownPC() MsgBox(1, "", "shutdown") EndFunc Func Terminate() Exit EndFunc Edited August 30, 2014 by Seminko Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 30, 2014 Moderators Share Posted August 30, 2014 Seminko,I am disappointed. > Select HearthCrawler Log folderGoogling tells me:Hearthcrawler. Bot for HearthstoneOver to you to convince me why I should not lock this thread. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Seminko Posted August 30, 2014 Author Share Posted August 30, 2014 Hey Melba, I know the forum rules: 1. Do not ask for help with AutoIt scripts, post links to, or start discussion topics on the following subjects: - Launching, automation or script interaction with games or game servers, regardless of the game. Now, I would like to clarify that this is NOT what I am trying to do there. What I'm creating is a script that would go through logs which are not generated by a game, collect the data from such logs and make a summary etc. etc. There is no launching, automation or script interaction with a game of any kind involved. Thank you Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 30, 2014 Moderators Share Posted August 30, 2014 Seminko,Fine - I was only asking. I will look at the script now. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Seminko Posted August 30, 2014 Author Share Posted August 30, 2014 (edited) OMG, just got it, it should call FolderCheck as well so the actual folder variable gets updated for FileSelect to work If $NewFileName <> "Log" Then $MyBox = MsgBox(4, "Cannot find a Log file", "There is no Log file in the folder selected. Is this the correct folder?" & @CRLF & @CRLF & "Press YES, If you are sure the folder is correct to Exit the script. Manually create a log." & @CRLF & @CRLF & "Press NO to reselect the folder.") If $MyBox = 6 Then Exit ElseIf $MyBox = 7 Then Call("FolderSelect") Call("FolderCheck") Call("FileSelect") EndIf EndIf Yay, I'm blind sometimes Edited August 30, 2014 by Seminko Link to comment Share on other sites More sharing options...
Moderators Solution Melba23 Posted August 30, 2014 Moderators Solution Share Posted August 30, 2014 (edited) Seminko,That is most definitely NOT the way to do it - you are recalling the FileSelect function from within itself, which is a recipe for disaster unless you are very careful. See the Recursion tutorial in the Wiki to understand why. Here is what I managed to cobble together from your existing code - as I would have done something very different altogether had I started from scratch:expandcollapse popup;#include <FileCountOccurrences.au3> #include <String.au3> #include <Array.au3> #include <Date.au3> #include <FileConstants.au3> #include <File.au3> ;#RequireAdmin Global $newfile = "" HotKeySet("{F8}", "Terminate") While $newfile = "" ; Keep looking until a file is found or the script exits $sFolder = FolderCheck() $newfile = FileSelect($sFolder) WEnd While 1 Local $WinCount = 0 ; _FileCountOccurrences($sFolder & $newfile, "Victory") If $WinCount >= 1 Then ShutdownPC() EndIf Sleep(2000) WEnd Func FolderCheck() Global $sFolder = IniRead("config.ini", "Path", "Log", "") If $sFolder = "" Then $sFolder = FolderSelect() EndIf EndFunc ;==>FolderCheck Func FileSelect($sFolder) $last = 0 $newfile = "" $aFiles = _FileListToArray($sFolder, "*", 1) ; Check if there are any files returned If IsArray($aFiles) Then For $i = 1 To $aFiles[0] $time = FileGetTime($sFolder & "\" & $aFiles[$i], 0, 1) If $time > $last Then Global $newfile = $aFiles[$i] $last = $time EndIf Next EndIf $newfile = StringLeft($newfile, 3) If $newfile = "Log" Then ; Return the file to end the loop Return $newfile Else Switch MsgBox(4, "Cannot find a Log file", "There is no Log file in the folder selected. Is this the correct folder?" & @CRLF & @CRLF & "Press YES, If you are sure the folder is correct to Exit the script. Manually create a log." & @CRLF & @CRLF & "Press NO to reselect the folder.") Case 6 Exit Case 7 ; Clear selected folder to force new search IniWrite("config.ini", "Path", "Log", "") ; Return empty string to force a new loop Return "" EndSwitch EndIf EndFunc ;==>FileSelect Func FolderSelect() Local Const $sMessage = "Select HearthCrawler Log folder." $sFileSelectFolder = FileSelectFolder($sMessage, "") If @error Then MsgBox(1, "", "No folder was selected.") Exit Else IniWrite("config.ini", "Path", "Log", $sFileSelectFolder & "\") Return $sFileSelectFolder EndIf EndFunc ;==>FolderSelect Func ShutdownPC() MsgBox(1, "", "shutdown") EndFunc ;==>ShutdownPC Func Terminate() Exit EndFunc ;==>TerminateSee if that works for you - it does for me within the limits of my testing (no real log file). M23P.S. And PLEASE stop using Call! Edited August 30, 2014 by Melba23 Typo Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Seminko Posted August 30, 2014 Author Share Posted August 30, 2014 (edited) Unfortunately, that does not work for me. Having the same issue I created this thread for. When I select a wrong folder, and press NO in the MsgBox to reselect the folder, there is an endless loop of msgboxes even though the correct folder has been selected. But the original thing works for me. I'll check on recursion. Why is 'Call' bad? Edited August 30, 2014 by Seminko Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 30, 2014 Moderators Share Posted August 30, 2014 Seminko,How very strange - evidently the script works perfectly for me or I would not have posted it. As to Call: why make AutoIt work harder then it has to? By using Call you force the string name to be parsed and then compared to existing functions - using the function name directly allows the interpreter to go straight there. Call should only really be used when the function name has to be in string format - when compiled from other elements for example. Of course the script will still work if you use Call - but it is not considered good practice to use it when it is not necessary. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Seminko Posted August 30, 2014 Author Share Posted August 30, 2014 Thanks Melba! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now