Clay Posted May 16, 2008 Posted May 16, 2008 Hey guys I need some help with creating some better logic. Here's the scoop: I have a script that grabs filenames from a database and then seperates the filename and fileversion number then calls another function that downloads the executable file from a webservice based on the filename and version # and then automates the setup process of that .exe file(the script is a little mopre complicated than that but I am trying to keep this simple so I don't loose you guys). However I just discovered a bug in my script. I have the following condition in the script Where $FileDetect is the name of the .exe file in the directory ....eg. ice_amp_r5.3.4.exe $FileDetect = _PathSplit($FindExe, $szDrive, $szDir, $szFName, $szExt) $pkgNameArray = Stringsplit( $szFName,"_") $TTProduct_Name = $pkgNameArray[1] If $TTProduct_Name = "ice" or "XTsim" or "PP" or "X" Then $pkgIDArray = _StringBetween( $FindExe, "_r", ".exe") $TTProduct_PackageID = $pkgIDArray[0] $prodversion = StringLeft($TTProduct_PackageID, 3) Else $pkgIDArray = _StringBetween( $FindExe, "_", ".exe") $TTProduct_PackageID = $pkgIDArray[0] $fullversion = StringTrimLeft($TTProduct_PackageID, 1) $prodversion = StringLeft($fullversion, 3) EndIF The problem I encounter is that my condition does not work for products such as DD_repel_r3.4.2 and others similar since the logical places epel_r3.4.2 in the $TTProduct_PackageID variable when I want r3.4.2 It also places epe in $prodversion when I want 3.4 I have searched but can't seem to find any existing functions -In Autoit -that might help me....Any logic advice would be appreciated. What would be the best way to have this work for all cases. Possible cases include: ice_amp_r5.3.4.exe DD_repel_r3.4.2 PP_Trade_r5.1.2 Xxam_r3.7.5 etc...
ProgAndy Posted May 16, 2008 Posted May 16, 2008 (edited) Use StringRegexp, so it works. The Version consists only out of Points and Numbers And it ends with a digit. $file = "ice_amp_r5.3.4.exe" $Number = StringRegExp($file,"_r([0-9.]*\d)",1) If IsArray($Number) Then $Number = $Number[0] MsgBox(0, '', $Number) Edited May 16, 2008 by ProgAndy *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes
PsaltyDS Posted May 16, 2008 Posted May 16, 2008 Use StringRegexp, so it works. The Version consists only out of Points and Numbers And it ends with a digit. $file = "ice_amp_r5.3.4.exe" $Number = StringRegExp($file,"_r([0-9.]*\d)",1) If IsArray($Number) Then $Number = $Number[0] MsgBox(0, '', $Number) I think StringRegExp() is the right idea, but some may not be familiar enough with it. Another way to fix your script using ordinary string manipulation is to find the location of "_r" searching from the RIGHT end. Use an occurrence parameter of -1 with StrigInStr(): $file = "ice_amp_r5.3.4.exe" $iVer = StringInStr($file, "_r", 0, -1) $sVer = StringMid($file, $iVer + 1) If StringRight($sVer, 4) = ".exe" Then $sVer = StringTrimRight($sVer, 4) MsgBox(0, '', $sVer) Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Clay Posted May 16, 2008 Author Posted May 16, 2008 (edited) Works.... thanks a bunch.... I hadn't a look of the StringRegExp function before.... thanks for the heads up Thanks Prog and Psalty Edited May 16, 2008 by Clay
Clay Posted May 16, 2008 Author Posted May 16, 2008 Psalty you are right StringRegExp() is a little confusing.... for me atleast. I am trying to understand this thing because now I want the other half of the string "ice_amp" and I can't seem to figure out a proper pattern I hate asking for the explicit answer when coding, but could one of you guys help me with the pattern to achieve this or explain the _r([0-9.]*\d) pattern and maybe I can take it from there. Is this thing saying match any 0-9 digit after _r and then escape after that?
Clay Posted May 16, 2008 Author Posted May 16, 2008 Psalty you are right StringRegExp() is a little confusing.... for me atleast. I am trying to understand this thing because now I want the other half of the string "ice_amp" and I can't seem to figure out a proper pattern I hate asking for the explicit answer when coding, but could one of you guys help me with the pattern to achieve this or explain the _r([0-9.]*\d) pattern and maybe I can take it from there. Is this thing saying match any 0-9 digit after _r and then escape after that? I can't get the damn "_r5" out $file = "tt_cdemei_r5.3.4.exe" $Number = StringRegExp($file,"([^0-9.]*\d)",1) If IsArray($Number) Then $Number = $Number[0] MsgBox(0, '', $Number)
PsaltyDS Posted May 16, 2008 Posted May 16, 2008 I can't get the damn "_r5" out $file = "tt_cdemei_r5.3.4.exe" $Number = StringRegExp($file,"([^0-9.]*\d)",1) If IsArray($Number) Then $Number = $Number[0] MsgBox(0, '', $Number) If you have time to figure out the RegExp patterns, it is well worth it. But in the interim: Global $avFiles[3] = [2, "tt_cdemei_r5.3.4.exe", "ice_amp_r5.3.4.exe"] For $n = 1 To UBound($avFiles) - 1 $iVer = StringInStr($avFiles[$n], "_r", 0, -1) $sVer = StringMid($avFiles[$n], $iVer + 1) If StringRight($sVer, 4) = ".exe" Then $sVer = StringTrimRight($sVer, 4) $sName = StringMid($avFiles[$n], 1, $iVer - 1) MsgBox(64, 'Results', "$sName = " & $sName & " $sVer = " & $sVer) Next Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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