peter1234 Posted February 6, 2006 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
Oxin8 Posted February 6, 2006 Posted February 6, 2006 peter1234 said: 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
peter1234 Posted February 6, 2006 Author Posted February 6, 2006 I did try searching first (I always do), but there were no results. Can you suggest what to search for?
Shibuya Posted February 6, 2006 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!!!"
peter1234 Posted February 6, 2006 Author Posted February 6, 2006 Shibuya, Thanks. I will check that out.
Oxin8 Posted February 6, 2006 Posted February 6, 2006 peter1234 said: 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
peter1234 Posted February 6, 2006 Author 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
Valuater Posted February 6, 2006 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)
peter1234 Posted February 6, 2006 Author Posted February 6, 2006 Valuater, Thanks. I haven't got time to test it now. I will do it tomorrow.
JerryD Posted February 6, 2006 Posted February 6, 2006 Oxin8 said: 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!
peter1234 Posted February 7, 2006 Author 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
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