peter1234 Posted February 6, 2006 Share Posted February 6, 2006 (edited) Is there a way to replace a line of text in a text file using AutoIt? I want to replace "XXXXX" in a text file with a file name such as "File=C:\video.m2v". Edited February 6, 2006 by peter1234 Link to comment Share on other sites More sharing options...
Oxin8 Posted February 6, 2006 Share Posted February 6, 2006 Is there a way to replace a line of text in a text file using AutoIt? I want to replace "XXXXX" in a text file with a file name such as "File=C:\video.m2v".This has been covered before. You should have tried searching first. If the file is an .ini , there are function specificly for it and they all can be found in the help file. If the neither search nor the help file does it, try posting the text file you want to change and we'll go from there. ~My Scripts~ *********_XInput UDF for Xbox 360 ControllerSprayPaint_MouseMovePlus Link to comment Share on other sites More sharing options...
peter1234 Posted February 6, 2006 Author Share Posted February 6, 2006 I did try searching first (I always do), but there were no results. Can you suggest what to search for? Link to comment Share on other sites More sharing options...
Shibuya Posted February 6, 2006 Share Posted February 6, 2006 Do a _FileReadtoArray, there's where you should start. Need I explain more for the rest? The speed of sound is defined by the distance from door to computer divided by the time interval needed to close the media player and pull up your pants when your mom shouts "OH MY GOD WHAT ARE YOU DOING!!!" Link to comment Share on other sites More sharing options...
peter1234 Posted February 6, 2006 Author Share Posted February 6, 2006 Shibuya, Thanks. I will check that out. Link to comment Share on other sites More sharing options...
Oxin8 Posted February 6, 2006 Share Posted February 6, 2006 I did try searching first (I always do), but there were no results. Can you suggest what to search for? I didn't just underline "searching" for no reason. lol. It's a link. Click to get the search I used ~My Scripts~ *********_XInput UDF for Xbox 360 ControllerSprayPaint_MouseMovePlus Link to comment Share on other sites More sharing options...
peter1234 Posted February 6, 2006 Author Share Posted February 6, 2006 Oxin8, Sorry! I missed that. Link to comment Share on other sites More sharing options...
peter1234 Posted February 6, 2006 Author Share Posted February 6, 2006 I wasn't able to get _FileReadToArray to work for me yet and I need to do something else now. But, I did find another way to do it. This uses a free program called TedNPad.exe which is a NotePad alternative. ;repalces this text "XXXXX" with the this text "File=C:\video.m2v" in the text file "c:\project.txt" $insert_this_text = "File=C:\video.m2v" run ( "TedNPad.exe" ) sleep(200) send ("^o") send ("c:\project.txt",1) send ("{ENTER}") sleep(200) send ("^r") send ("XXXXX" ,1) send ("{TAB}") send ($insert_this_text ,1) send ("{TAB}") send ("{TAB}") send ("{TAB}") send ("{ENTER}") send ("{TAB}") send ("{TAB}") send ("{ENTER}") send ("^s") sleep(200) send ("{ESC}") exit Link to comment Share on other sites More sharing options...
Valuater Posted February 6, 2006 Share Posted February 6, 2006 not tested... but should work Dim $aRecords Dim $aFile = "c:\project.txt" Dim $Old_info = "XXXXX" Dim $New_info = "File=C:\video.m2v" GuiCreate("MY GUI") $input = GUICtrlCreateEdit("" , 20, 20, 350, 300) If Not _FileReadToArray($aFile,$aRecords) Then MsgBox(4096,"Error", " Error reading log to Array error:" & @error) Exit EndIf For $x = 1 to $aRecords[0] If StringInStr($aRecords[$x], $Old_info) Then $aRecords[$x] = $New_info GUICtrlSetData( $input, $aRecords[$x] & @CRLF, 1) Next $Check= GUICtrlCreateButton("Exit", 150,350,100,30) GUISetState(); display the GUI While 1 $msg = GUIGetMsg() Select Case $msg= $Check Exit Case $msg= $GUI_EVENT_CLOSE Exit EndSelect WEnd 8) Link to comment Share on other sites More sharing options...
peter1234 Posted February 6, 2006 Author Share Posted February 6, 2006 Valuater, Thanks. I haven't got time to test it now. I will do it tomorrow. Link to comment Share on other sites More sharing options...
Valuater Posted February 6, 2006 Share Posted February 6, 2006 no prob 8) Link to comment Share on other sites More sharing options...
JerryD Posted February 6, 2006 Share Posted February 6, 2006 I didn't just underline "searching" for no reason. lol. It's a link. Click to get the search I used I did notice that, and was impressed with the search results, but it's a fish - not a fishing lesson! Link to comment Share on other sites More sharing options...
peter1234 Posted February 7, 2006 Author Share Posted February 7, 2006 (edited) Valuater, This is what I ended up with. Your suggestion failed to replace text but showed me what to do. Thanks for your help (I needed it). By the way, that was a very neat GUI suggestion. ; Creates new text file that has the text "XXXXX" replaced with the text "ABCDE" #include <GUIConstants.au3> #include<file.au3> #include<array.au3> Dim $text_array $old_file = "project.txt" $new_info = "ABCDE" $old_info = "XXXXX" FileOpen($old_file,0) If Not _FileReadToArray($old_file,$text_array) Then MsgBox(4096,"Error", " Error reading log to Array error:" & @error) FileClose($old_file) Exit EndIf FileDelete ("new_project.txt") $new_file = FileOpen("new_project.txt",1) For $x = 1 to $text_array[0] $match = StringInStr($text_array[$x], $old_info) If $match<>0 Then $text_array[$x] = StringReplace ( $text_array[$x], $old_info, $new_info ) FileWrite($new_file, $text_array[$x] & @CRLF ) Next FileClose($new_file) FileClose($old_file) Edited February 7, 2006 by peter1234 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