Sign in to follow this  
Followers 0
bobheart

Can you use this to read a file ?

6 posts in this topic

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 .

Share this post


Link to post
Share on other sites



i didnt realy understand what you mean??

are you looking for a line:

bob.txt

?

if yes why not to use loop and check every line?

Share this post


Link to post
Share on other sites

Yes the txt file is almost 3 mb so I don't want to look thur it so how would I use a loop to find bob.txt in a txt file or if it is in there .

Share this post


Link to post
Share on other sites

$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)


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Got this

$chars = FileRead($file)
$chars = ^ ERROR

Error: Incorrect number of parameters in function call.

Share this post


Link to post
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
Sign in to follow this  
Followers 0