hellemon Posted November 13, 2005 Share Posted November 13, 2005 Hello together,This is my first Script with AutoIT, and i have a little problem and hope you can help me. Examplei have a CFG File (test.cfg) with the following entries#wcontrolserver:<servername1>,<10.0.0.100>computerid:1234g0jmacadresse:001100110022and i have a other textfile (servername.txt) with the new servername entries<servername2>,<10.0.0.102>I would like to change the <servername> and <ip adresse> in the CFG Filehow can i make thatThis is my Script but it is not working$servername = FileOpen("servername.txt", 0) $var = FileReadLine($servername) FileReadLine ("servername.txt", 1) FileClose($servername) ;############################## $cfgfile = FileOpen("test.cfg", 1) FileWriteLine($cfgfile, "server:$var") FileClose($cfgfile)thank you very muchHellemon Link to comment Share on other sites More sharing options...
Gene Posted November 13, 2005 Share Posted November 13, 2005 (edited) Hello together,This is my first Script with AutoIT, and i have a little problem and hope you can help me. Examplei have a CFG File (test.cfg) with the following entries#wcontrolserver:<servername1>,<10.0.0.100>computerid:1234g0jmacadresse:001100110022and i have a other textfile (servername.txt) with the new servername entries<servername2>,<10.0.0.102>I would like to change the <servername> and <ip adresse> in the CFG Filehow can i make thatThis is my Script but it is not working$servername = FileOpen("servername.txt", 0) $var = FileReadLine($servername) FileReadLine ("servername.txt", 1) FileClose($servername) ;############################## $cfgfile = FileOpen("test.cfg", 1) FileWriteLine($cfgfile, "server:$var") FileClose($cfgfile)thank you very muchHellemonFirst, you shouldn't have posted this request in this Forum! It should have been in the Support Forum! If you continue to post help requests in the wrong place, you'll just get a lot of people yelling at you and no help!That said, you might try:$var1 = FileRead("servername.txt", FileGetSize ( "servername.txt" )) ;############################## $var2 = FileRead("test.cfg", FileGetSize ( "test.cfg" )) $iVar1 = StringInStr($var2,"<",0,1) $iVar2 = StringInStr($var2,">",0,2) $iStrLen = $iVar2 -$iVar1 + 1 $sSearchStr = StringMid($var2,$iVar1,$iStrLen) $sVar3 = StringReplace ( $var2, $sSearchStr, $var1 ) FileMove("test.cfg","Test.cfg.old",9) FileWrite("test.cfg",$sVar3)This worked for me with your example files, I didn't do any error checking but you should.From looking at your examples, I'm not sure this is what you want, but it is what I understood you to ask for. Edited November 13, 2005 by Gene [font="Verdana"]Thanks for the response.Gene[/font]Yes, I know the punctuation is not right... Link to comment Share on other sites More sharing options...
hellemon Posted November 14, 2005 Author Share Posted November 14, 2005 Hello Gene, Thanks for you help, but it´s not really what i want. But it´s OK. Thanks and Have a Lot of fun Hellemon Link to comment Share on other sites More sharing options...
jefhal Posted November 15, 2005 Share Posted November 15, 2005 how can i make thatGet the new and old server names by grabbing the lines in each file that start with "server:", then use _ReplaceStringInFile to replace oldstring with newstring. ...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format Link to comment Share on other sites More sharing options...
Gene Posted November 15, 2005 Share Posted November 15, 2005 Hello Gene,Thanks for you help, but it´s not really what i want. But it´s OK.Thanks and Have a Lot of funHellemonMaybe you should give a more complete example of what you want to do.If your files have more data than you showed, give more records of the set for each file, so it's clear what end result you want, and what the environment is. [font="Verdana"]Thanks for the response.Gene[/font]Yes, I know the punctuation is not right... Link to comment Share on other sites More sharing options...
hellemon Posted November 15, 2005 Author Share Posted November 15, 2005 Hello Gene, Thank you, but i found the solution..... expandcollapse popup; Neuen Server holen und in Variable $newserver speichern $fileserver = FileOpen("server.txt",0) ; Überprüft ob die server.txt geöffnet werden kann If $fileserver = -1 Then MsgBox(0, "Fehler", "Kann server.txt nicht öffnen.") Exit EndIf $newserver = FileReadLine($fileserver) FileClose($fileserver) $file = FileOpen("wcontrol.cfg", 0) ; Überprüft ob die wcontrol.cfg geöffnet werden kann If $file = -1 Then MsgBox(0, "Fehler", "Kann wcontrol.cfg nicht öffnen.") Exit EndIf ; Legt neue Datei wcontrol.new an $filenew = fileOpen("wcontrol.new", 2) ; Überprüft ob die wcontrol.new geöffnet werden kann If $filenew = -1 Then MsgBox(0, "Fehler", "Kann wcontrol.new nicht öffnen.") Exit EndIf ; Neue Datei wcontrol.new schreiben While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop If StringLeft($line,6)="Server" Then $line="Server=" & $newserver EndIf $result=FileWriteLine($filenew, $line) if $result=0 then MsgBox(0, "Fehler", "Kann wcontrol.new nicht schreiben.") FileClose($file) FileClose($filenew) FileDelete("wcontrol.new") Exit EndIf Wend FileClose($file) FileClose($filenew) ; Der Schreibschutz von der datei wcontrol.cfg wird empfernt FileSetAttrib("wcontrol.cfg", "-R", 0) If @error Then MsgBox(4096,"Fehler", "Schreibschutz von der wcontrol.cfg kann nicht empfernen werden.") Exit EndIf FileMove("wcontrol.new", "wcontrol.cfg",1) Hava Fun regards, Helmut Link to comment Share on other sites More sharing options...
Gene Posted November 16, 2005 Share Posted November 16, 2005 Hello Gene,Thank you, but i found the solution.....expandcollapse popup; Neuen Server holen und in Variable $newserver speichern $fileserver = FileOpen("server.txt",0) ; Überprüft ob die server.txt geöffnet werden kann If $fileserver = -1 Then MsgBox(0, "Fehler", "Kann server.txt nicht öffnen.") Exit EndIf $newserver = FileReadLine($fileserver) FileClose($fileserver) $file = FileOpen("wcontrol.cfg", 0) ; Überprüft ob die wcontrol.cfg geöffnet werden kann If $file = -1 Then MsgBox(0, "Fehler", "Kann wcontrol.cfg nicht öffnen.") Exit EndIf ; Legt neue Datei wcontrol.new an $filenew = fileOpen("wcontrol.new", 2) ; Überprüft ob die wcontrol.new geöffnet werden kann If $filenew = -1 Then MsgBox(0, "Fehler", "Kann wcontrol.new nicht öffnen.") Exit EndIf ; Neue Datei wcontrol.new schreiben While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop If StringLeft($line,6)="Server" Then $line="Server=" & $newserver EndIf $result=FileWriteLine($filenew, $line) if $result=0 then MsgBox(0, "Fehler", "Kann wcontrol.new nicht schreiben.") FileClose($file) FileClose($filenew) FileDelete("wcontrol.new") Exit EndIf Wend FileClose($file) FileClose($filenew) ; Der Schreibschutz von der datei wcontrol.cfg wird empfernt FileSetAttrib("wcontrol.cfg", "-R", 0) If @error Then MsgBox(4096,"Fehler", "Schreibschutz von der wcontrol.cfg kann nicht empfernen werden.") Exit EndIf FileMove("wcontrol.new", "wcontrol.cfg",1)Hava Funregards, HelmutGreat! [font="Verdana"]Thanks for the response.Gene[/font]Yes, I know the punctuation is not right... 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