flinchy Posted August 23, 2009 Share Posted August 23, 2009 (edited) Hey all im new here but im finding Autoit pretty easy to pick up and the only thing i cant do is something i think should be easy compared to other stuff ive done with it... Is there a way to search through a file for some text and if it isnt there then it is written... I know that the FileWriteLine("file here", @LF & "Text to add to the end") is needed... But i cant work out the If command for the rest... I have tried If FileReadLine($hostPath & "\hosts", "127.0.0.1 facebook.com") = false Then FileWriteLine($hostPath & "\hosts", @LF & "127.0.0.1 facebook.com") End If but it doesnt work >_< any help? Cheers Flinchy Edit: The finding of "127.0.0.1 facebook.com" can be ANYWHERE in the file as long as it doesnt have a # in front of it but if it doesnt exist it is added to the end... Edited August 23, 2009 by flinchy Link to comment Share on other sites More sharing options...
Hawkwing Posted August 23, 2009 Share Posted August 23, 2009 $filetext = FileRead($filepath) If Not StringInStr($filetext, $textyourlookingfor) Then FileWriteLine($hostPath & "\hosts", @LF & "127.0.0.1 facebook.com") EndIf Just wrote this real quick, so it may not work, but it should give you the general idea of what you need to do. The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again. Link to comment Share on other sites More sharing options...
flinchy Posted August 23, 2009 Author Share Posted August 23, 2009 (edited) $filetext = FileRead($filepath) If Not StringInStr($filetext, $textyourlookingfor) Then FileWriteLine($hostPath & "\hosts", @LF & "127.0.0.1 facebook.com") EndIf Just wrote this real quick, so it may not work, but it should give you the general idea of what you need to do. Thanks ill give it a go now and let you know how it works out >_< Edit: It works perfectly thanks alot Edited August 23, 2009 by flinchy 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