TheCrimsonCrusader Posted May 19, 2009 Share Posted May 19, 2009 I am wanting to read the contents of one text file (c:\readfile.txt) and then should the contents of the c:\readfile.txt exist in another file (c:\writefile.txt), have those contents deleted from the c:\writefile.txt.So after reading the contents of c:\readfile.txt, which is:Sentence 1Sentence 2Sentence 3Sentence 4Sentence 5If at least the same contents exist in c:\writefile.txt as shown below:Sentence 1Sentence 2Sentence 3Sentence 4Sentence 5Sentence 6Sentence 7Sentence 8Sentence 9Sentence 10Then c:\writefile.txt would be edited to look like the following:Sentence 6Sentence 7Sentence 8Sentence 9Sentence 10============================================I understand the string search and replace option when specifying a specific string to replace, but not when reading the entire file contents to then have it replaced in another file should the same contents exist. I tried the code below, but I wasn't confident it would work despite it looking logical to me. Any ideas? The file might be better off being read to an array, but I still wasn't grasping the concept of getting the contents replaced in the other file should the contents exist. Thanks for any assistance on this.CODE#include <File.au3>$readfile=FileRead("c:\readfile.txt")_ReplaceStringInFile("c:\writefile.txt",$readfile,"") Link to comment Share on other sites More sharing options...
TurionAltec Posted May 19, 2009 Share Posted May 19, 2009 In file.au3, the _ReplaceStringInFile function reads the input function and splits it in an array according to lines (separations of @CR). Your search query spans multiple lines so it will never have a match. Maybe you can concoct your own function from StringReplace() and StringInStr() $file1=FileRead("c:\readfile.txt") $file2=FileRead("c:\writefile.txt") If StringInStr($file1, $file2) Then $file2=StringReplace($file2, $file1, "") $handle=FileOpen("c:\writefile.txt", 2) Filewrite($handle, $file2) FileClose($handle) Endif Link to comment Share on other sites More sharing options...
FinalVersion Posted May 19, 2009 Share Posted May 19, 2009 _FileReadToArray() [center][+] Steam GUI [+][+] Clipboard Tool [+][+] System :: Uptime [+][+] StarCraft II Mouse Trap [+][/center] 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