Hypertrophy Posted July 11, 2009 Share Posted July 11, 2009 I have a .txt file that is about 1000 lines long and is constantly being added to when I am running a 3rd part application. I also have an .ini file that has 3 keys that I want to look for in that .txt file. How would I read in all the data in that text file and then match it to see if my keys (SOME or ALL) are also written in that txt file and if so, display a msgbox() for each one. I know I need FileRead(), and IniReadSection() maybe? Don't know how to go about this... Link to comment Share on other sites More sharing options...
KaFu Posted July 11, 2009 Share Posted July 11, 2009 (edited) 1000 lines is not too long, read it all to a single string, then do a stringinstr search, something like this $hFile = FileOpen("test.txt", 0) If $hFile = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf $sFile = FileRead($hFile) FileClose($hFile) Select Case StringInStr($sFile, "A") > 0 And StringInStr($sFile, "B") > 0 And StringInStr($sFile, "C") > 0 MsgBox(0, "", "All flags found") Case StringInStr($sFile, "A") > 0 MsgBox(0, "", "Flag A found") Case StringInStr($sFile, "B") > 0 MsgBox(0, "", "Flag B found") Case StringInStr($sFile, "C") > 0 MsgBox(0, "", "Flag C found") EndSelect Edit: Maybe this is even more efficient, didn't test it though ... $hFile = FileOpen("test.txt", 0) If $hFile = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf $sFile = FileRead($hFile) FileClose($hFile) $iFoundA = StringInStr($sFile, "A") $iFoundB = StringInStr($sFile, "B") $iFoundC = StringInStr($sFile, "C") Select Case $iFoundA > 0 AND $iFoundB > 0 AND $iFoundC > 0 MsgBox(0, "", "All flags found") Case $iFoundA > 0 MsgBox(0, "", "Flag A found") Case $iFoundB > 0 MsgBox(0, "", "Flag B found") Case $iFoundC > 0 MsgBox(0, "", "Flag C found") EndSelect Edited July 11, 2009 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) 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