PsaltyDS Posted August 20, 2008 Share Posted August 20, 2008 (edited) using 3.2.10.0its part of a larger script that works only in this version =/Time to update that script. There's no reason to recompile a script that works, but if you are actively maintaining it, then it needs to be updated to the current version. What about your script only works in 3.2.10.0?shame on me for doubting you salty. i did find it strange --So did I, everybody knows I don't make such mistakes... Edited August 20, 2008 by PsaltyDS 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 Link to comment Share on other sites More sharing options...
Country73 Posted August 20, 2008 Share Posted August 20, 2008 Still a bit of a noob here, but have you tried looking at: #Include <File.au3> _FileWriteToLine($sFile, $iLine, $sText[, $fOverWrite = 0]) $sFile The file to write to $iLine The line number to write to $sText The text to write $fOverWrite If set to 1 will overwrite the old line If set to 0 will not overwrite Once you've located the line you want to replace, then put that line number for the $iLine. Just taking a stab at this. If you try to fail and succeed which have you done?AutoIt Forum Search Link to comment Share on other sites More sharing options...
gcue Posted August 20, 2008 Author Share Posted August 20, 2008 it's nearly 8000 lines..the last time i tried compiling it in something newer than 3.2.10 was at least 3,000 lines ago and several things werent working right =/Time to update that script. There's no reason to recompile a script that works, but if you are actively maintaining it, then it needs to be updated to the current version. What about your script only works in 3.2.10.0?So did I, everybody knows I don't make such mistakes... Link to comment Share on other sites More sharing options...
gcue Posted August 20, 2008 Author Share Posted August 20, 2008 problem is we dont know the exact line # to rename Still a bit of a noob here, but have you tried looking at: #Include <File.au3> _FileWriteToLine($sFile, $iLine, $sText[, $fOverWrite = 0]) $sFile The file to write to $iLine The line number to write to $sText The text to write $fOverWrite If set to 1 will overwrite the old line If set to 0 will not overwrite Once you've located the line you want to replace, then put that line number for the $iLine. Just taking a stab at this. Link to comment Share on other sites More sharing options...
Monamo Posted August 20, 2008 Share Posted August 20, 2008 (edited) using 3.2.10.0 its part of a larger script that works only in this version =/I'm still stuck using 3.2.10.0 in the office as well (work mandate). OK, so I know that you mentioned that the keys themselves must be in a specific order within the section. Do the Sections themselves have to be maintained in a specific order in the "larger script" you're using? If not, give this a try: Existing INI file example (test.ini in the script directory): [Section1] Key1=Value1 Key2=Value2 Key3=Value3 [Section2] Key1=Value1 Key2=Value2 Key3=Value3 [Section3] Key1=Value1 Key2=Value2 Key3=Value3 $iRet = _IniRenameKey($sINIFile, "Section2", "Key2", "RenamedKey2") ConsoleWrite("Return code = " &$iRet &@CRLF) Func _IniRenameKey($sFile, $sSection, $sKeyOld, $sKeyNew) ;Return values ; 0 = Success ; 1 = Old key doesn't exist in the specified section ; 2 = New key name already in use in the specified section ; 3 = File is readonly ; 4 = File doesn't exist If Not FileExists($sFile) Then Return 4 $iOldMarker = 0 $aSection = IniReadSection($sFile, $sSection) For $i = 1 To $aSection[0][0] If $aSection[$i][0] = $sKeyOld Then $iOldMarker = $i If $aSection[$i][0] = $sKeyNew Then Return 2 EndIf Next If $iOldMarker = 0 Then Return 1 Else $aSection[$iOldMarker][0] = $sKeyNew IniDelete($sFile,$sSection) For $i = 1 To $aSection[0][0] If Not IniWrite($sFile,$sSection,$aSection[$i][0],$aSection[$i][1]) Then Return 3 Next EndIf EndFunc Edited August 20, 2008 by Monamo - MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup] Link to comment Share on other sites More sharing options...
gcue Posted August 20, 2008 Author Share Posted August 20, 2008 works! thanks mate. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted August 20, 2008 Moderators Share Posted August 20, 2008 Demo: $sIniData = "[Section Name One]" & @CRLF & _ "one = 1" & @CRLF & _ "two = 2" & @CRLF & _ "three = 3" & @CRLF & _ "[Section Name Two]" & @CRLF & _ "one = 1" & @CRLF & _ "two = 2" & @CRLF & _ "three = 3" & @CRLF & _ "[Section Name Three]" & @CRLF & _ "one = 1" & @CRLF & _ "two = 2" & @CRLF & _ "three = 3" MsgBox(64, "Before", $sIniData) $sSection = "[Section Name Two]" $sKeySearch = "two" $sKeyReplace = "KeyTwo" $iSecLoc = StringInStr($sIniData, $sSection, 0, 1) + StringLen($sSection) $iKeyLoc = StringInStr($sIniData, $sKeySearch & " = ", 0, 1, $iSecLoc) $sIniData = StringMid($sIniData, 1, $iKeyLoc - 1) & $sKeyReplace & " = " & _ StringMid($sIniData, $iKeyLoc + StringLen($sKeySearch & " = ")) MsgBox(64, "After", $sIniData) StringRegExpReplace() would be geekier, but it doesn't support non-capturing groups as I understand it, which really hurts its utility for things like this. It doesn't? Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
PsaltyDS Posted August 20, 2008 Share Posted August 20, 2008 (edited) It doesn't?Cough...Ahem... Edited August 20, 2008 by PsaltyDS 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 Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted August 20, 2008 Moderators Share Posted August 20, 2008 (edited) Cough... Ahem... Oh yeah... lol. I use ?: for that anymore, but it's more to separate my back references Anyway: StringRegExpReplace():$sIniData = "[Section Name One]" & @CRLF & _ "one = 1" & @CRLF & _ "two = 2" & @CRLF & _ "three = 3" & @CRLF & _ "[Section Name Two]" & @CRLF & _ "one = 1" & @CRLF & _ "two = 2" & @CRLF & _ "three = 3" & @CRLF & _ "[Section Name Three]" & @CRLF & _ "one = 1" & @CRLF & _ "two = 2" & @CRLF & _ "three = 3" ;MsgBox(64, "Before", $sIniData) $sSection = "Section Name Two" $sKeySearch = "two" $sKeyReplace = "KeyTwo" $s_ini_data = StringRegExpReplace($sIniData, "(?i)(?s)((?:\A|\n)\s*\[\s*)(" & $sSection & ")(\s*\]\s*\r.*?\n\s*)(?:\z|\[|(" & $sKeySearch & ")(\s*=))", "\1\2\3" & $sKeyReplace & "\5") MsgBox(64, "After", $s_ini_data)Was that what you were after? Edit: Oops, I saw what your concern was, hopefully that fixed it. Edited August 20, 2008 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
PsaltyDS Posted August 20, 2008 Share Posted August 20, 2008 Oh yeah... lol. I use ?: for that anymore, but it's more to separate my back references Anyway: StringRegExpReplace():$sIniData = "[Section Name One]" & @CRLF & _ "one = 1" & @CRLF & _ "two = 2" & @CRLF & _ "three = 3" & @CRLF & _ "[Section Name Two]" & @CRLF & _ "one = 1" & @CRLF & _ "two = 2" & @CRLF & _ "three = 3" & @CRLF & _ "[Section Name Three]" & @CRLF & _ "one = 1" & @CRLF & _ "two = 2" & @CRLF & _ "three = 3" ;MsgBox(64, "Before", $sIniData) $sSection = "Section Name Two" $sKeySearch = "two" $sKeyReplace = "KeyTwo" $s_ini_data = StringRegExpReplace($sIniData, "(?i)(?s)((?:\A|\n)\s*\[\s*)(" & $sSection & ")(\s*\]\s*\r.*?\n\s*)(?:\z|\[|(" & $sKeySearch & ")(\s*=))", "\1\2\3" & $sKeyReplace & "\5") MsgBox(64, "After", $s_ini_data)Was that what you were after? Edit: Oops, I saw what your concern was, hopefully that fixed it. Looks like it works to me... and you are such a geek! 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 Link to comment Share on other sites More sharing options...
gcue Posted August 21, 2008 Author Share Posted August 21, 2008 works great! thanks smoke! Oh yeah... lol. I use ?: for that anymore, but it's more to separate my back references Anyway: StringRegExpReplace():$sIniData = "[Section Name One]" & @CRLF & _ "one = 1" & @CRLF & _ "two = 2" & @CRLF & _ "three = 3" & @CRLF & _ "[Section Name Two]" & @CRLF & _ "one = 1" & @CRLF & _ "two = 2" & @CRLF & _ "three = 3" & @CRLF & _ "[Section Name Three]" & @CRLF & _ "one = 1" & @CRLF & _ "two = 2" & @CRLF & _ "three = 3" ;MsgBox(64, "Before", $sIniData) $sSection = "Section Name Two" $sKeySearch = "two" $sKeyReplace = "KeyTwo" $s_ini_data = StringRegExpReplace($sIniData, "(?i)(?s)((?:\A|\n)\s*\[\s*)(" & $sSection & ")(\s*\]\s*\r.*?\n\s*)(?:\z|\[|(" & $sKeySearch & ")(\s*=))", "\1\2\3" & $sKeyReplace & "\5") MsgBox(64, "After", $s_ini_data)Was that what you were after? Edit: Oops, I saw what your concern was, hopefully that fixed it. 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