Johannes13 Posted June 29, 2021 Share Posted June 29, 2021 Hello all, I searched for this or a similar topic but could not find anything. I am quite new to AutoIT, so if I searched in a wrong way please redirect me. We have installed different versions of the same application. The decision about the version is just by its folder. f.e. C:\Software\Program 2.3\app\windows\program.exe C:\Software\Program 2.8\app\windows\program.exe C:\Software\Program 4.3\app\windows\program.exe The .exe itself is always in the same directory inside the version folder and has always the same name. I am looking for a possibility to automatically start the latest version of the program.exe application. Right now I use "Run" together with the path. If a new version of the program.exe is installed I have to manually adapt my AutoIt script which becomes annoying after some time. My idea would be that AutoIt looks for the highest Program version number (=latest version) in the C:\Software\ folder and executes the program.exe. Is this possible using AutoIt? If not - another option, if possible, would be to display all installed folders (Versions) over a GUI at the beginning of the script and the user has to select the latest one manually. Thanks in advice Link to comment Share on other sites More sharing options...
Jfish Posted June 29, 2021 Share Posted June 29, 2021 (edited) You could read the directories into an array, parse the strings in a loop to find the highest program # value, and then execute the exe in that directory. Another idea is to use the date of the newest folder in the directory containing all these versions. The newest date is the one you should run. The below example uses an array with the directories which you can get with _FileListToArray. I just hard coded them to show an example of parsing. #include <String.au3> #include <Array.au3> global $dirs[3]=["C:\Software\Program 2.3\app\windows\program.exe","C:\Software\Program 2.8\app\windows\program.exe","C:\Software\Program 4.3\app\windows\program.exe"] ; create array with all the dirs - replace this with a function for $a=0 to ubound($dirs)-1 ; loop through the array global $finder=_StringBetween($dirs[$a],"C:\Software\Program ","\app\windows\program.exe") ; find the version and isolate if @error then ; check for errors MsgBox("","error",@error) EndIf _ArrayDisplay($finder) ; display result to screen Next P.S. Yes, you can display the folders - but if you can display the folders you already have the strings to work with to determine the latest version 😉 Edited June 29, 2021 by Jfish Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt Link to comment Share on other sites More sharing options...
Luke94 Posted June 29, 2021 Share Posted June 29, 2021 (edited) Assuming the installation directories are as you've stated, using _FileListToArrayRec with $FLTAR_SORT should result in the last item been the latest version. #include <Array.au3> #include <File.au3> Global $g_sDir = 'C:\Software' Global $g_aFolders Global $g_sLastFolder $g_aFolders = _FileListToArrayRec($g_sDir, Default, $FLTAR_FOLDERS, Default, $FLTAR_SORT, $FLTAR_FULLPATH) If @ERROR Then ConsoleWrite('ERROR: _FileListToArrayRec' & @CRLF) Exit EndIf $g_sLastFolder = $g_aFolders[$g_aFolders[0]] ConsoleWrite('Running: "' & $g_sLastFolder & '\app\windows\program.exe"') Run($g_sLastFolder & '\app\windows\program.exe') Edit: This would only work up until version 9.9. 😢 Edited June 29, 2021 by Luke94 Link to comment Share on other sites More sharing options...
Solution Nine Posted June 29, 2021 Solution Share Posted June 29, 2021 (edited) Assuming that the versioning is only based on 2 parts (xx.xx) : #include <File.au3> Const $sRoot = "C:\Apps\Temp" Local $aFolders = _FileListToArrayRec($sRoot, "Software*", $FLTAR_FOLDERS, Default, Default, $FLTAR_FULLPATH) _ArrayDisplay($aFolders) Local $aVersion, $iFirst, $iLast, $iHighest For $i = 1 to $aFolders[0] $aVersion = StringRegExp($aFolders[$i], "Software (\d*).(\d*)", 1) If Number($aVersion[0]) > $iFirst Or (Number($aVersion[0]) = $iFirst And Number($aVersion[1]) > $iLast) Then $iFirst = Number($aVersion[0]) $iLast = Number($aVersion[1]) $iHighest = $i EndIf Next MsgBox(0, $iHighest, $aFolders[$iHighest]) Run($aFolders[$iHighest] & "\app\windows\program.exe") Edited June 29, 2021 by Nine Earthshine 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Johannes13 Posted June 29, 2021 Author Share Posted June 29, 2021 1 hour ago, Luke94 said: Assuming the installation directories are as you've stated, using _FileListToArrayRec with $FLTAR_SORT should result in the last item been the latest version. #include <Array.au3> #include <File.au3> Global $g_sDir = 'C:\Software' Global $g_aFolders Global $g_sLastFolder $g_aFolders = _FileListToArrayRec($g_sDir, Default, $FLTAR_FOLDERS, Default, $FLTAR_SORT, $FLTAR_FULLPATH) If @ERROR Then ConsoleWrite('ERROR: _FileListToArrayRec' & @CRLF) Exit EndIf $g_sLastFolder = $g_aFolders[$g_aFolders[0]] ConsoleWrite('Running: "' & $g_sLastFolder & '\app\windows\program.exe"') Run($g_sLastFolder & '\app\windows\program.exe') Edit: This would only work up until version 9.9. 😢 Thanks for that solution - works fine but the problem is I have to go beyond version 10. Link to comment Share on other sites More sharing options...
Johannes13 Posted June 29, 2021 Author Share Posted June 29, 2021 Thanks all for your fast reply. @Nine Your solution works perfect for me. Thanks Link to comment Share on other sites More sharing options...
Johannes13 Posted June 29, 2021 Author Share Posted June 29, 2021 1 hour ago, Nine said: Assuming that the versioning is only based on 2 parts (xx.xx) : #include <File.au3> Const $sRoot = "C:\Apps\Temp" Local $aFolders = _FileListToArrayRec($sRoot, "Software*", $FLTAR_FOLDERS, Default, Default, $FLTAR_FULLPATH) _ArrayDisplay($aFolders) Local $aVersion, $iFirst, $iLast, $iHighest For $i = 1 to $aFolders[0] $aVersion = StringRegExp($aFolders[$i], "Software (\d*).(\d*)", 1) If Number($aVersion[0]) > $iFirst Or (Number($aVersion[0]) = $iFirst And Number($aVersion[1]) > $iLast) Then $iFirst = Number($aVersion[0]) $iLast = Number($aVersion[1]) $iHighest = $i EndIf Next MsgBox(0, $iHighest, $aFolders[$iHighest]) Run($aFolders[$iHighest] & "\app\windows\program.exe") I am just trying to edit your solution to 3 parts (xx.xx.xx) but I am a bit brainfucked by the and/or connections right now Do you have a quick solution for 3 parts? Link to comment Share on other sites More sharing options...
Luke94 Posted June 29, 2021 Share Posted June 29, 2021 #include <File.au3> Const $sRoot = "C:\Apps\Temp" Local $aFolders = _FileListToArrayRec($sRoot, "Software*", $FLTAR_FOLDERS, Default, Default, $FLTAR_FULLPATH) _ArrayDisplay($aFolders) Local $aVersion, $iFirst, $iMid, $iLast, $iHighest For $i = 1 to $aFolders[0] $aVersion = StringRegExp($aFolders[$i], "Software (\d*).(\d*).(\d*)", 1) If Number($aVersion[0]) > $iFirst Or (Number($aVersion[0]) = $iFirst And Number($aVersion[1]) > $iMid And Number($aVersion[2]) > $iLast) Then $iFirst = Number($aVersion[0]) $iMid = Number($aVersion[1]) $iLast = Number($aVersion[2]) $iHighest = $i EndIf Next MsgBox(0, $iHighest, $aFolders[$iHighest]) Run($aFolders[$iHighest] & "\app\windows\program.exe") Credits to @Nine Link to comment Share on other sites More sharing options...
Johannes13 Posted June 29, 2021 Author Share Posted June 29, 2021 9 minutes ago, Luke94 said: #include <File.au3> Const $sRoot = "C:\Apps\Temp" Local $aFolders = _FileListToArrayRec($sRoot, "Software*", $FLTAR_FOLDERS, Default, Default, $FLTAR_FULLPATH) _ArrayDisplay($aFolders) Local $aVersion, $iFirst, $iMid, $iLast, $iHighest For $i = 1 to $aFolders[0] $aVersion = StringRegExp($aFolders[$i], "Software (\d*).(\d*).(\d*)", 1) If Number($aVersion[0]) > $iFirst Or (Number($aVersion[0]) = $iFirst And Number($aVersion[1]) > $iMid And Number($aVersion[2]) > $iLast) Then $iFirst = Number($aVersion[0]) $iMid = Number($aVersion[1]) $iLast = Number($aVersion[2]) $iHighest = $i EndIf Next MsgBox(0, $iHighest, $aFolders[$iHighest]) Run($aFolders[$iHighest] & "\app\windows\program.exe") Credits to @Nine I think for 3 levels its not that easy. I just created a test setup with empty folders and it says that 10.2.4 is the highest version, although 10.3.3. is higher. Link to comment Share on other sites More sharing options...
Luke94 Posted June 29, 2021 Share Posted June 29, 2021 (edited) What about this? Works for me. #include <File.au3> Const $sRoot = "C:\Apps\Temp" Local $aFolders = _FileListToArrayRec($sRoot, "Software*", $FLTAR_FOLDERS, Default, Default, $FLTAR_FULLPATH) _ArrayDisplay($aFolders) Local $aVersion, $iFirst, $iMid, $iLast, $iHighest For $i = 1 to $aFolders[0] $aVersion = StringRegExp($aFolders[$i], "Software (\d*).(\d*).(\d*)", 1) If Number($aVersion[0]) > $iFirst Or (Number($aVersion[0]) = $iFirst And Number($aVersion[1]) > $iMid) Or (Number($aVersion[0]) = $iFirst And Number($aVersion[1]) = $iMid And Number($aVersion[2]) > $iLast) Then $iFirst = Number($aVersion[0]) $iMid = Number($aVersion[1]) $iLast = Number($aVersion[2]) $iHighest = $i EndIf Next MsgBox(0, $iHighest, $aFolders[$iHighest]) Run($aFolders[$iHighest] & "\app\windows\program.exe") Credits to @Nine again. ☺️ Edited June 29, 2021 by Luke94 Link to comment Share on other sites More sharing options...
Johannes13 Posted July 5, 2021 Author Share Posted July 5, 2021 Thanks @Luke94 now it finds the file and executes it correctly. Only one additional thing. To run the program.exe correctly it requires the path of the program.exe file as "workingdir" when using the Run function. Is there an easy way to edit the found path and automatically remove the last "TEC.exe" part of the path. Because to run the .exe I need to execute the "Run" command with "C:\REC\TEC7\app\tec\windows\" as working directory otherwise the application gives me an error during startup. It only works when Run is executed like this: Local $path = "C:\TEC\TEC7\app\tec\windows\" Run($path & "TEC.exe", $path, @SW_MAXIMIZE ) Link to comment Share on other sites More sharing options...
Luke94 Posted July 5, 2021 Share Posted July 5, 2021 Run($aFolders[$iHighest] & "\app\windows\program.exe", $aFolders[$iHighest] & "\app\windows\") For the most recent code posted by Nine and edited by me. You may need to change the "\app\windows\" bit. Link to comment Share on other sites More sharing options...
Johannes13 Posted July 5, 2021 Author Share Posted July 5, 2021 Thanks for the hint. I found now a other solution that worked for me $sPath = StringReplace($aFolders[$iHighest],"\TEC.txt","\") Run ( "notepad.exe " & $aFolders[$iHighest], $sPath, @SW_MAXIMIZE ) Link to comment Share on other sites More sharing options...
Nine Posted July 5, 2021 Share Posted July 5, 2021 (edited) A more generic SRER : $path = StringRegExpReplace($aFolders[$iHighest], "[^\\]+$", "") It will keep the path removing whatever file name there is... Edited July 5, 2021 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Johannes13 Posted July 5, 2021 Author Share Posted July 5, 2021 Is it possible to ignore the sign between "TEC" and the version number? I tested the script on a other PC where one version was installed in a folder using "_" instead of space between TEC and the version. The best would be if it only checks for the version number and ignores TEC at all. But when I use it like this: $aVersion = StringRegExp($aFolders[$i], "(\d*).(\d*).(\d*)", 1) instead of this (working fine as long as format is "TEC version" and not "TEC_version" or a mix) : $aVersion = StringRegExp($aFolders[$i], "TEC (\d*).(\d*).(\d*)", 1) It only returns "4" from row 0 as it does not find a version at all and the rest of the rows stay empty. Can someone help me with the syntax on that? Thanks for your help Link to comment Share on other sites More sharing options...
Nine Posted July 5, 2021 Share Posted July 5, 2021 Change to : $aVersion = StringRegExp($aFolders[$i], "TEC[ _](\d*).(\d*).(\d*)", 1) “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy 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