Jump to content

Can you use this to read a file ?


Recommended Posts

I want to find is a file name is in a txt file but not sure how to read a file ?

$file = FileOpen("test.txt", 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

; Read in 1 character at a time until the EOF is reached
While 1
    $chars = FileRead($file, 1)
    If @error = -1 Then ExitLoop
    MsgBox(0, "Char read:", $chars)
Wend

FileClose($file)

I don't want to read it one line at a time I want to see if a line is in that file .

the line "bob.txt" is in a myfile.txt .

Link to comment
Share on other sites

  • Developers

$file = FileOpen("test.txt", 0)

; Check if file opened for reading OK
If $file = -1 Then
   MsgBox(0, "Error", "Unable to open file.")
   Exit
EndIf

; Read in 1 character at a time until the EOF is reached
While 1
   $chars = FileRead($file)
   If @error = -1 Then ExitLoop
   if stringinstr($char,"bob.txt") then MsgBox(0, "Char read:", $chars)
Wend

FileClose($file)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...