Trong Posted December 13, 2015 Share Posted December 13, 2015 (edited) How to Find the largest version of a list of version numbers? ;For TEST DirCreate("1.2.6.4") DirCreate("1.1.2.4") DirCreate("1.0.3.4") DirCreate("1.5.0.4") DirCreate("1.6.7.4") ;For TEST END #include <Misc.au3> #include <File.au3> Local $sListVer,$sListFile = _FileListToArray(@ScriptDir, "*", 2, 0) For $x = 1 To UBound($sListFile) - 1 If StringInStr($sListFile[$x],".") Then ConsoleWrite($sListFile[$x]&@CRLF) $sListVer&=$sListFile[$x]&"|" EndIf Next Local $sVerList = StringSplit($sListVer,"|") If UBound($sVerList) > 1 Then For $x = 1 To UBound($sVerList) - 1 ConsoleWrite($sVerList[$x]&@CRLF) ;ConsoleWrite(_VersionCompare ( "", "" )&@CRLF) Next EndIf ;For TEST DirRemove("1.2.6.4") DirRemove("1.1.2.4") DirRemove("1.0.3.4") DirRemove("1.5.0.4") DirRemove("1.6.7.4") ;For TEST END# Edited December 14, 2015 by Trong Regards, Link to comment Share on other sites More sharing options...
water Posted December 13, 2015 Share Posted December 13, 2015 Use _VersionCompare and write the largest version into a variable. After the end of the loop the variable holds the largest version. Trong 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
MilesAhead Posted December 13, 2015 Share Posted December 13, 2015 (edited) For a generalized way of sorting with a user defined comparison function, see #7 in this threadfor the attachment ArraySortCustom.au3Edit: In fact the example compare function is for dot separated version strings Edited December 13, 2015 by MilesAhead Trong 1 My Freeware Page Link to comment Share on other sites More sharing options...
JohnOne Posted December 13, 2015 Share Posted December 13, 2015 #include <Array.au3> $sVersions = "1.2.6.4|1.1.2.4|1.0.3.4|1.5.0.4|1.6.7.4" $aVersions1 = StringSplit($sVersions, "|", 2) _ArraySort($aVersions1, 1) MsgBox(0, "Latest version", $aVersions1[0]) Trong 1 AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
MilesAhead Posted December 13, 2015 Share Posted December 13, 2015 (edited) #include <Array.au3> $sVersions = "1.2.6.4|1.1.2.4|1.0.3.4|1.5.0.4|1.6.7.4" $aVersions1 = StringSplit($sVersions, "|", 2) _ArraySort($aVersions1, 1) MsgBox(0, "Latest version", $aVersions1[0]) This works in your example but not if the sample version strings have a higher number in a version compnent that starts with a character lower in the sort order. As example 3.3.2.4 would be seen as higher than 3.12.2.4 That is why in the example comparison function I split out the version components and converted them to numbers. Edited December 13, 2015 by MilesAhead Trong 1 My Freeware Page Link to comment Share on other sites More sharing options...
JohnOne Posted December 14, 2015 Share Posted December 14, 2015 Agreed.I just coded it down a bit to fit.Stringreplace the "." and sort it as an int. Trong 1 AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
MilesAhead Posted December 14, 2015 Share Posted December 14, 2015 (edited) Agreed.I just coded it down a bit to fit.Stringreplace the "." and sort it as an int.Sorry. I looked at your code without really seeing it. Must've been a pre-coffee scan. Edited December 14, 2015 by MilesAhead Double text fix. Trong 1 My Freeware Page Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted December 14, 2015 Share Posted December 14, 2015 Agreed.I just coded it down a bit to fit.Stringreplace the "." and sort it as an int.That would still break if the lower number is longer$versionett = "3.3.8.1" $versiontva = "3.2.12.0" $versionett = Int(StringReplace($versionett, ".", "")) $versiontva = Int(StringReplace($versiontva, ".", "")) ConsoleWrite("$versionett is higher than $versiontva? " & ($versionett > $versiontva) & @CRLF)You must split the parts like _VersionCompare is doing if the comparison is going to work Trong 1 .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
Gianni Posted December 14, 2015 Share Posted December 14, 2015 have a look here for one of possible ways: https://www.autoitscript.com/forum/topic/166640-how-to-format-the-output-of-the-autoitversion-macro/p.s.how could be modified Yashied's regex, (from post #7 of above topic) so to have numbers padded with zero for a total of 3 digits in length instead of only 2 ?? Trong 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
TheDcoder Posted December 14, 2015 Share Posted December 14, 2015 Not sure if its what you want :#include <File.au3> #include <MsgBoxConstants.au3> Local Const $FOLDER = @ScriptDir ; Folder to check DirCreate("1.2.6.4") DirCreate("1.1.2.4") DirCreate("1.0.3.4") DirCreate("1.5.0.4") DirCreate("1.6.7.4") Local $aVersions = _FileListToArray($FOLDER, "*.*.*.*", $FLTA_FOLDERS) Local $iLatestVersionsIndex = 0 For $i = 1 To $aVersions[0] If Number(StringReplace($aVersions[$iLatestVersionsIndex], '.', "")) < Number(StringReplace($aVersions[$i], '.', "")) Then $iLatestVersionsIndex = $i EndIf Next MsgBox($MB_OK, "Latest Version", $aVersions[$iLatestVersionsIndex]) DirRemove("1.2.6.4") DirRemove("1.1.2.4") DirRemove("1.0.3.4") DirRemove("1.5.0.4") DirRemove("1.6.7.4")TD Trong 1 EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion 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