ArmandoXS 0 Posted June 1, 2010 (edited) i think the topic description is very self explainatory, I was thinking of using FileWriteLine but im not sure on how to remove whats there and then aswell save it Edited June 1, 2010 by DarkDragon Share this post Link to post Share on other sites
Shakala 0 Posted June 1, 2010 If you have the name of the file, and you know the text you want to change, you can use this simple text replace code $TextFileName = "test.txt" ; Name of the file $FindText = "HEllo" ;Text you want to find $ReplaceText = "Good Bye" ; TExt you want to replace it with $FileContents = FileRead($TextFileName) ;Reads all the information in the text file $FileContents = StringReplace($FileContents, $FindText, $ReplaceText) ; reads filecontents, finds the text you want to remove, puts ReplaceText in its place FileDelete($TextFileName) ; Deletes the file FileWrite($TextFileName, $FileContents);Remakes the file with the new content If you want to let the user change the text you want to read and replace, then there is a few more lines you have to add, just reply if this solved your problem or if you want me to go into more complicated stuff. Share this post Link to post Share on other sites
ArmandoXS 0 Posted June 1, 2010 (edited) If you have the name of the file, and you know the text you want to change, you can use this simple text replace code $TextFileName = "test.txt" ; Name of the file $FindText = "HEllo" ;Text you want to find $ReplaceText = "Good Bye" ; TExt you want to replace it with $FileContents = FileRead($TextFileName) ;Reads all the information in the text file $FileContents = StringReplace($FileContents, $FindText, $ReplaceText) ; reads filecontents, finds the text you want to remove, puts ReplaceText in its place [color="#FFFF00"]FileDelete($TextFileName) ; Deletes the file FileWrite($TextFileName, $FileContents);Remakes the file with the new content If you want to let the user change the text you want to read and replace, then there is a few more lines you have to add, just reply if this solved your problem or if you want me to go into more complicated stuff. Crystal Clear Thanks exept when its says file delete and file read will the only things that were changed be deleted and rewritten or will the whole text file screw up?? Edited June 1, 2010 by DarkDragon Share this post Link to post Share on other sites
Shakala 0 Posted June 1, 2010 Nope, It keeps the whole file intact, with the new line just inserted where it should be Because it reads the contents of the file, replaces the few lines of text then it saves all of the text under FIleContents and when it rewrites it, it used the File Contents to keep it all intact Share this post Link to post Share on other sites
ArmandoXS 0 Posted June 1, 2010 (edited) ok... but do i need the filedelete??? im a little confused b/c it appears that ur just deleting the varible itself (or the name of the file , not the actual file) Edited June 1, 2010 by DarkDragon Share this post Link to post Share on other sites
Shakala 0 Posted June 1, 2010 (edited) Honestly, im not sure. I'll look into it a bit more for you. I'm not a pro at coding in autoit yet, but none the less, the code works. Edit: You are deleting the file, so you can remake it with the correct information If you dont delete it, it will just put the redone information under the current information Edited June 1, 2010 by Shakala Share this post Link to post Share on other sites
ArmandoXS 0 Posted June 1, 2010 Honestly, im not sure. I'll look into it a bit more for you.I'm not a pro at coding in autoit yet, but none the less, the code works.ok thanks for the help Share this post Link to post Share on other sites
stevie 0 Posted June 9, 2010 If you have the name of the file, and you know the text you want to change, you can use this simple text replace codeIf you want to let the user change the text you want to read and replace, then there is a few more lines you have to add, just reply if this solved your problem or if you want me to go into more complicated stuff.Hi guys.I just registered to this forum as this topic is almost exactly what I was looking for and I also wanted to thank you.However, as I am absolutely new to AutoIt and as this topic only "almost exactly" solves my problem, please allow an additional question to the one by DarkDragon:Is there a way of finding and replacing whole text blocks, i.e. text that is expanded to several lines within a txt-based file? To be more precisely: I have 2 txt-based files and need to copy one (or more) text blocks from file a to b. Any help would be appreciated. Share this post Link to post Share on other sites