Shedunn Posted February 8, 2018 Share Posted February 8, 2018 So this is my issue...my work makes this software that creates a new folder with all the same file names every time it is updated. I want to find the most RECENT version of an EXE file that can be found within those folders. So I have a folder (Ie. Program files) Within "Program files" are more folders (Ie. 1, 2, 3) with extremely long names for each new version of the software Within "1', "2", and "3" are files with the EXACT same names but new or old versions. So as an example each folder has "readme.txt", "run.exe", and some other files. I just want the Newest version of "run.exe" out of all the subdirectories of Program files I've been trying to figure this out for about a day now and haven't come up with anything yet even after looking through different forums. Not sure if I'm just not searching the right terms or what. Link to comment Share on other sites More sharing options...
BrewManNH Posted February 8, 2018 Share Posted February 8, 2018 FileGetTime used in conjuntion with _FileListToArrayRec. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
jdelaney Posted February 8, 2018 Share Posted February 8, 2018 Or FileGetVersion. IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
Shedunn Posted February 8, 2018 Author Share Posted February 8, 2018 If you were going to use the "FileGetTime" with "_FileListToArrayRec" , what would that look like? I just need an example to look at how you would use them both together Link to comment Share on other sites More sharing options...
Subz Posted February 8, 2018 Share Posted February 8, 2018 Shedunn 1 Link to comment Share on other sites More sharing options...
xcaliber13 Posted February 8, 2018 Share Posted February 8, 2018 I have to find the latest version of files too. After searching these forums I found and use this: ; #FUNCTION# ==================================================================================================================== ; Name ..........: _FileVersion Func _FileVersion($sFilePath, $sMask = "*.*", $iFlag = 0, $bFormat = True) Local $aFileList = _FileListToArrayRec($sFilePath, $sMask, 1, 0, 0, 2) If @error Then Return 0 Local $aFileVersion[0][4] _ArrayAdd($aFileVersion, UBound($aFileList) - 1 & "|Modified|Created|Accessed") For $i = 1 to $aFileList[0] _ArrayAdd($aFileVersion, $aFileList[$i] & "|" & FileGetTime($aFileList[$i], 0, 1) & "|" & FileGetTime($aFileList[$i], 1, 1) & "|" & FileGetTime($aFileList[$i], 2, 1)) Next Switch $iFlag Case 1 _ArraySort($aFileVersion, 1, 1, 0, 2) Case 2 _ArraySort($aFileVersion, 1, 1, 0, 3) Case Else _ArraySort($aFileVersion, 1, 1, 0, 1) EndSwitch Return $bFormat = True ? $aFileVersion : $aFileVersion[1][0] EndFunc ; End of FUNCTION ================================================================================================================= Wish I could remember who wrote it and give credit to them. Just call the Function Local $LatestFileCreated = _FileVersion("C:\Temp", "Run.exe", 1, False) Change c:\Temp to your directory. Change Run.exe to what ever file you are looking for. I use wildcards because all the files are named the same with random numbers at the end. I use a *.* $LatestFileCreated will show the path and file of the latest one. I don't have to search sub folders so not sure if it does. Hope this helps you Link to comment Share on other sites More sharing options...
Shedunn Posted February 9, 2018 Author Share Posted February 9, 2018 Thank you guys! I will try these later when I get home. Link to comment Share on other sites More sharing options...
Shedunn Posted February 9, 2018 Author Share Posted February 9, 2018 (edited) So...Here is my code. I'm definitely new to AutoIT and I'm having a hard time figuring out how to implement your code examples into my own code. expandcollapse popup;Asks for and sets blueprint 3 version Global $BP3Version = InputBox('bluePrint3 Version Input', 'Please enter the version number in this format: "0.0.0.0"', '3.3.0', '') Global $bluePrint3 = 'bluePRINT 3 - Version ' Global $PageTitle = $bluePrint3 & $BP3Version AutoItSetOption('MouseCoordMode' , 0) ;if user clicks cancel the script quits If $BP3Version = '' Then Exit EndIf $YesNo = msgBox(3,'bluePRINT3 version you chose', 'You chose ' & $BP3Version & ' Is this correct?') ;If user selects No it will keep asking for version and verifying until user clicks yes or cancel While $YesNo = 7 $BP3Version = InputBox('Re-enter your version', 'Please Re-Enter your bluePRINT3 version number in this format: "0.0.0.0"', '3.3.0', '') If $BP3Version = '' Then Exit EndIf $YesNo = msgBox(3,'bluePRINT3 version you chose', 'You chose ' & $BP3Version & ' Is this correct?') WEnd ;If user clicks cancel script quits If $YesNo = 2 then Exit ;If user clicks yes the script continues ElseIf $YesNo = 6 then Run(@ScriptDir & '\bluePRINT3.exe', '', @SW_MAXIMIZE) EndIf WinWait($PageTitle) WinActivate($PageTitle) ;CLICKS CONTROL PANEL SETUP MouseClick('primary', 339,204, 1, 0) ;SELECTS CP PORT PANEL MouseClick('primary', 615,116, 1, 0) Send('{DOWN 2}', '{ENTER}') Sleep( 2000) Where it says "Run(@ScriptDir & '\bluePRINT3.exe', '', @SW_MAXIMIZE)" I would like it to Find the last created "bluePRINT3.exe" file out of all the subdirectories in C:\Users\sdunn\AppData\Local\Apps\2.0 and then run it. Edited February 9, 2018 by Shedunn Realized I went too far in my file path Link to comment Share on other sites More sharing options...
Subz Posted February 10, 2018 Share Posted February 10, 2018 Here is one way to do it: expandcollapse popup#include <Array.au3> #include <ComboConstants.au3> #include <File.au3> #include <GUIConstantsEx.au3> _bluePRINT3() Func _bluePRINT3() Local $iMsgBox Local $aBluePRINT3 = _FileListToArrayRec(@LocalAppDataDir & "\Apps\2.0", "bluePRINT3.exe", 1, 1, 1, 2) If @error Then Exit MsgBox(16, "bluePRINT3", "Unable to find bluePRINT3.exe files under " & @LocalAppDataDir & "\Apps\2.0") Local $aBP3Version[$aBluePRINT3[0]][2] For $i = 1 To $aBluePRINT3[0] $aBP3Version[$i-1][0] = $aBluePRINT3[$i] $aBP3Version[$i-1][1] = "bluePRINT 3 - Version " & FileGetVersion($aBluePRINT3[$i]) Next _ArraySort($aBP3Version, 1, 0, 0, 1) $sBP3Version = _ArrayToString($aBP3Version, "|", -1, -1, "|", 1) Local $hGUI = GUICreate("bluePRINT3", 190, 70) Local $idComboBox = GUICtrlCreateCombo("", 10, 10, 170, 20, $CBS_DROPDOWNLIST) GUICtrlSetData($idComboBox, $sBP3Version, $aBP3Version[0][1]) Local $idClose = GUICtrlCreateButton("Close", 10, 35, 85, 25) Local $idStart = GUICtrlCreateButton("Start", 95, 35, 85, 25) GUISetState(@SW_SHOW, $hGUI) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idClose ExitLoop Case $idStart $iBP3Version = _ArraySearch($aBP3Version, GUICtrlRead($idComboBox)) If @error Then ContinueLoop $iMsgBox = MsgBox(36, GUICtrlRead($idComboBox), "About to run: " & @CRLF & $aBP3Version[$iBP3Version][0] & @CRLF & "Do you want to continue?") Switch $iMsgBox Case 7 ContinueLoop Case 6 Run($aBP3Version[$iBP3Version][0]) AutoItSetOption('MouseCoordMode' , 0) WinWait(GUICtrlRead($idComboBox)) WinActivate(GUICtrlRead($idComboBox)) ;CLICKS CONTROL PANEL SETUP MouseClick('primary', 339,204, 1, 0) ;SELECTS CP PORT PANEL MouseClick('primary', 615,116, 1, 0) Send('{DOWN 2}', '{ENTER}') Sleep( 2000) EndSwitch EndSwitch WEnd GUIDelete($hGUI) Exit EndFunc Link to comment Share on other sites More sharing options...
Shedunn Posted February 10, 2018 Author Share Posted February 10, 2018 Your example finds the file and opens it! Which is exactly what I wanted. The only issue I have now is that the dialogue box asking for user input for the version number is changed and I'm not sure what parts of your example I have to change to make it back to the way it was but leave the file opening part working. The input box was there because the title of the application window has the version number in it and I was using it to reference the window for mouse clicks. The version number is different between the external release(public 3 digits 3.3.0) and the internal release(4 digits 3.3.0.3). Link to comment Share on other sites More sharing options...
Shedunn Posted February 10, 2018 Author Share Posted February 10, 2018 (edited) The version number is typically something we would know before running the application . If I can call the app window without the full version number using a wildcard or something I would do that but I'm not sure how to apply a wildcard to an app window title "bluePRINT 3 - Version 3. " & *.* maybe???idk Sorry I'm not trying to be a pain in the ass I swear. lol Edited February 10, 2018 by Shedunn I put in quotes but meant to put in stars Link to comment Share on other sites More sharing options...
Shedunn Posted February 10, 2018 Author Share Posted February 10, 2018 Alright I found another forum that was talking about Opt("WinTitleMatchMode", 2) So I think I may be able to do away without the dialogue boxes in my original code Link to comment Share on other sites More sharing options...
Subz Posted February 10, 2018 Share Posted February 10, 2018 Not sure I understand correctly, so do you only want the latest bluePRINT3.exe to open, it's unrelated to the version input? Link to comment Share on other sites More sharing options...
Shedunn Posted February 10, 2018 Author Share Posted February 10, 2018 Yes completely unrelated to the version input, just need the latest bluePRINT3.exe to open Link to comment Share on other sites More sharing options...
Subz Posted February 10, 2018 Share Posted February 10, 2018 Understand now, I'll make a couple of changes and update soon. Link to comment Share on other sites More sharing options...
Shedunn Posted February 10, 2018 Author Share Posted February 10, 2018 Awesome! Thank you Link to comment Share on other sites More sharing options...
Subz Posted February 10, 2018 Share Posted February 10, 2018 How about: expandcollapse popup#include <Array.au3> #include <File.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> _bluePRINT3() Func _bluePRINT3() Local $iMsgBox, $sBP3Version ;~ Getting the latest version of bluePRINT3.exe in @LocalAppDataDir\Apps\2.0 Local $aBluePRINT3 = _FileListToArrayRec(@LocalAppDataDir & "\Apps\2.0", "bluePRINT3.exe", 1, 1, 1, 2) If @error Then Exit MsgBox(16, "bluePRINT3", "Unable to find bluePRINT3.exe files under " & @LocalAppDataDir & "\Apps\2.0") Local $aBP3Version[$aBluePRINT3[0]][2] For $i = 1 To $aBluePRINT3[0] $aBP3Version[$i-1][0] = $aBluePRINT3[$i] $aBP3Version[$i-1][1] = FileGetVersion($aBluePRINT3[$i]) Next _ArraySort($aBP3Version, 1, 0, 0, 1) ;~ $aBP3Version[0][0] is the latest version of bluePRINT3.exe in @LocalAppDataDir\Apps\2.0 ;~ Gui Information Local $hGUI = GUICreate("bluePRINT3", 490, 70) GUICtrlCreateLabel('Please enter the version number in this format: "0.0.0.0"', 10, 10, 300, 20, $SS_CENTERIMAGE) Local $idBP3Version = GUICtrlCreateInput("3.3.0", 310, 10, 170, 20) Local $idClose = GUICtrlCreateButton("Close", 310, 35, 85, 25) Local $idStart = GUICtrlCreateButton("Start", 395, 35, 85, 25) GUISetState(@SW_SHOW, $hGUI) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idClose ExitLoop Case $idStart $sBP3Version = 'bluePRINT 3 - Version ' & GUICtrlRead($idBP3Version) $iMsgBox = MsgBox(36, "bluePRINT3 version you chose", "About to run: " & $sBP3Version & ". Do you want to continue?") Switch $iMsgBox Case 7 ContinueLoop Case 6 Run($aBP3Version[0][0]) AutoItSetOption('MouseCoordMode' , 0) WinWait($sBP3Version) WinActivate($sBP3Version) ;CLICKS CONTROL PANEL SETUP MouseClick('primary', 339,204, 1, 0) ;SELECTS CP PORT PANEL MouseClick('primary', 615,116, 1, 0) Send('{DOWN 2}', '{ENTER}') Sleep( 2000) EndSwitch EndSwitch WEnd GUIDelete($hGUI) Exit EndFunc Shedunn 1 Link to comment Share on other sites More sharing options...
Shedunn Posted February 10, 2018 Author Share Posted February 10, 2018 Thank you so much! You Sir(or ma'am) are awesome! 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