LuisMartins Posted December 20, 2012 Share Posted December 20, 2012 (edited) Hi there,So I got this .INF file, example:// Some text // Another text Version=1.0And I'm trying to get only the value 1.0 in my script.I tried:IniRead(@ScriptDir & "\myapp\version.inf", "", "version", "NULL")I guess it didn't work because it doesn't have sections like an .INI .I'm also trying FileSetPos but no luck with it. Any help?Thanks in advance! Edited December 20, 2012 by LuisMartins Link to comment Share on other sites More sharing options...
lopolop Posted December 20, 2012 Share Posted December 20, 2012 (edited) I believe you need a section in your .ini file. For example: [Description] Version=1.0 Edit: I see you mentioned that already. You'll have to parse it somehow. Edited December 20, 2012 by lopolop Link to comment Share on other sites More sharing options...
LuisMartins Posted December 20, 2012 Author Share Posted December 20, 2012 (edited) The thing is, the .INF file may be updated and I'd rather not have to edit it everytime to add a Section. And IniRead would be perfect, because it has this thing that when the value isn't found is assumes the defined default value, in my case "NULL". The closer I can get is with FileReadLine, which as the name says, gives me the line I want, but I still need just the value after Version= Edited December 20, 2012 by LuisMartins Link to comment Share on other sites More sharing options...
BrewManNH Posted December 20, 2012 Share Posted December 20, 2012 Unfortunately your INF file isn't in the correct format to be used with the INI* functions. In fact, it doesn't appear to be in the correct format for an INF file either, seeing as how the INF and INI formats are the same. You're going to have to do some parsing of the file, perhaps with FileRead and StringRegExp to determine if the version line is in there or not. LuisMartins 1 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...
kylomas Posted December 20, 2012 Share Posted December 20, 2012 LuisMartins, Here is a technique that you can build on (this is one of many ways to do this): #include <array.au3> ; create a test file to simulate your .INF file local $str = '// Some text' & @crlf & '// Another text' & @crlf & 'Version=1.0' & @crlf & 'more data of any kind' local $hfl = fileopen(@scriptdir & 'tmp010.inf',2) filewrite($hfl,$str) fileclose($hfl) $hfl = 0 ; read inf file to string local $str = fileread(@scriptdir & 'tmp010.inf') ; search for your string local $srch = stringregexp($str,'(?i)version.*',3) if @error = 1 then ConsoleWrite('String not found' & @LF) Exit endif ; display results _arraydisplay($srch) kylomas LuisMartins 1 Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
LuisMartins Posted December 20, 2012 Author Share Posted December 20, 2012 (edited) Thank you, both answers were useful.But still, my bad, forgot to mention, there's still one problem.I have another string before "Version=1.0", which is "firstversion=0.1", example:// Some text // Another text firstversion=0.1 Version=1.0So, assuming that its value may also get updated, I don't think I can really rely on StringRegExp, I guess. Edited December 20, 2012 by LuisMartins Link to comment Share on other sites More sharing options...
BrewManNH Posted December 20, 2012 Share Posted December 20, 2012 Maybe you should post a sanitized version of the complete file, this way we know what we're dealing with, and not having you move the goal posts whenever something is posted. LuisMartins 1 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...
LuisMartins Posted December 20, 2012 Author Share Posted December 20, 2012 // NetworkVersion is the version in the wire protcol between client<->server, // its not used for matchmaking, PatchVersion is used for that to ensure // we don't get cross connecting to different releases. Only bump this if // you know an incompatible change has happened to the network protocol in // game and old demos will not work. NetworkVersion=2.0.4.2 PatchVersion=2.1.1.8 ProductName=left4dead2 appID=550 My goal is to get the number 2.1.1.8 and only that number. Considering the versions may change with updates I want my application to always stay up to date whenever they change without having to do it manually myself. Link to comment Share on other sites More sharing options...
BrewManNH Posted December 20, 2012 Share Posted December 20, 2012 This is why you should have posted what you're actually looking at instead of being so obtuse in the first posts. This is only slightly like what you were asking for in the first place. The word version appears in that file several times. If we had known that before we could have come up with a much better answer for you earlier. local $str = fileread(@scriptdir & 'test.ini'); change this to your file name ; search for your string local $srch = stringregexp($str,'(?i)PatchVersion=(.*)',3) if @error = 1 then ConsoleWrite('String not found' & @LF) Exit endif _ArrayDisplay($srch) LuisMartins 1 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...
LuisMartins Posted December 20, 2012 Author Share Posted December 20, 2012 (edited) Ok thanks, that actually shows only the value. But I'm not able to compare the returned value of $srch with another value, like: If $srch = "2.1.1.7" Then MsgBox("", "Error", "Your version is not up-to-date.") EndIf Any advice? Edited December 20, 2012 by LuisMartins Link to comment Share on other sites More sharing options...
BrewManNH Posted December 20, 2012 Share Posted December 20, 2012 It returns an array, you'd need to write it like this. If $srch[0] = "2.1.1.7" Then MsgBox("", "Error", "Your version is not up-to-date.") EndIf LuisMartins 1 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...
LuisMartins Posted December 20, 2012 Author Share Posted December 20, 2012 Ok thank you again, it's working great now. Link to comment Share on other sites More sharing options...
guinness Posted December 20, 2012 Share Posted December 20, 2012 Just out of curiosity is the version number always a single digit e.g. d.d.d.d? UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
jdelaney Posted December 20, 2012 Share Posted December 20, 2012 may want to also add a boundry: #include <Array.au3> $str = "NetworkVersion=2.0.4.2" & @CRLF & _ "PatchVersion=2.1.1.8" & @CRLF & _ "LastPatchVersion=2.1.1.7" & @CRLF & _ "ProductName=left4dead2" & @CRLF & _ "appID=550" local $srch = stringregexp($str,'(?i)bPatchVersion=(.*)',3) _ArrayDisplay($srch) ; returns one result local $srch = stringregexp($str,'(?i)PatchVersion=(.*)',3) _ArrayDisplay($srch) ; returns two results LuisMartins 1 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...
BrewManNH Posted December 20, 2012 Share Posted December 20, 2012 may want to also add a boundry:Can't hurt, although not necessary if they don't use "PatchVersion=" anywhere else in the file. But better to play it safe. 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...
LuisMartins Posted December 20, 2012 Author Share Posted December 20, 2012 Just out of curiosity is the version number always a single digit e.g. d.d.d.d?Yes, it is. may want to also add a boundry: #include $str = "NetworkVersion=2.0.4.2" & @CRLF & _ "PatchVersion=2.1.1.8" & @CRLF & _ "LastPatchVersion=2.1.1.7" & @CRLF & _ "ProductName=left4dead2" & @CRLF & _ "appID=550" local $srch = stringregexp($str,'(?i)\bPatchVersion=(.*)',3) _ArrayDisplay($srch) ; returns one result local $srch = stringregexp($str,'(?i)PatchVersion=(.*)',3) _ArrayDisplay($srch) ; returns two resultsWell like I said, those versions will much probably get updated and therefere I can't rely setting them manually... Link to comment Share on other sites More sharing options...
jdelaney Posted December 20, 2012 Share Posted December 20, 2012 My example was just to demonstrate finding the actual data you need, when tokens exist with similar names. 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...
LuisMartins Posted December 20, 2012 Author Share Posted December 20, 2012 Thanks for the heads up. Link to comment Share on other sites More sharing options...
Exit Posted December 21, 2012 Share Posted December 21, 2012 (edited) $MyFile = "./~tempfile.inf" ; ; generate testfile ; FileWrite($MyFile, _ "// NetworkVersion is the version in the wire protcol between client<->server," & @CRLF & _ "// its not used for matchmaking, PatchVersion is used for that to ensure" & @CRLF & _ "// we don't get cross connecting to different releases. Only bump this if" & @CRLF & _ "// you know an incompatible change has happened to the network protocol in" & @CRLF & _ "// game and old demos will not work." & @CRLF & _ "NetworkVersion=2.0.4.2" & @CRLF & _ "PatchVersion=2.1.1.8" & @CRLF & _ "LastPatchVersion=2.1.1.7" & @CRLF & _ "ProductName=left4dead2" & @CRLF & _ "appID=550") ; ; here the working code ; IniWriteSection($MyFile&".tmp.ini","MyData",FileRead($MyFile)) $result=IniRead($MyFile&".tmp.ini","MyData","PatchVersion","0.0.0.0") FileDelete($MyFile&".tmp.ini") MsgBox(262144," ",$result,0) ; ; cleanup testfile ; FileDelete($MyFile) ; Edited December 21, 2012 by Exit App: Au3toCmd UDF: _SingleScript() 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