Jump to content

fileread


Recommended Posts

hi i have a file with 50 rules and on the 46 rule is standing a variable

i wanne make that i can search to that variable and read that rule how i can do that ?

so if on the 46 is standing hello

that i can enter in a inbox hello and that he is going to search and he found on rule 46 the words hello and then he needs to read that whole line and show it to me how i can do that ?

Link to comment
Share on other sites

$word=InputBox("word", "word")
$f=FileOpen("file.txt", 0)
$br=0
While 1
    $l = FileReadLine($f)
    If @error = -1 Then ExitLoop
    $br+=1
    if stringinstr($l, $word, 1)<>0 then Msgbox(0, "found", "I found your word in line " & $br)
Wend
FileClose($f)

;) ?

Edited by muhmuuh

I ran. I ran until my muscles burned and my veins pumped battery acid. Then I ran some more.

Link to comment
Share on other sites

$word=InputBox("word", "word")
$f=FileOpen("file.txt", 0)
$br=0
While 1
    $l = FileReadLine($f)
    If @error = -1 Then ExitLoop
    $br+=1
    if stringinstr($l, $word, 1)<>0 then Msgbox(0, "found", "I found your word in line " & $br)
Wend
FileClose($f)

;) ?

hmm nice but how i can say read that file example now he found that i searched on line 2 how i can say read line 2 ?
Link to comment
Share on other sites

$word=InputBox("word", "word")
$f=FileOpen("file.txt", 0)
$br=0
While 1
    $l = FileReadLine($f)
    If @error = -1 Then ExitLoop
    $br+=1
    if stringinstr($l, $word, 1)<>0 then Msgbox(0, "found", "I found your word in line " & $br)
Wend
FileClose($f)

;) ?

hmm nice but how i can say read that file example now he found that i searched on line 2 how i can say read line 2 ?

p.s. why i cant search @ line 1 he dont find what i search on line one?

its not importend that i know with rule it is.. i just need to be able to read that entire rule that what i need

find the line containing the words i look for and read that entire rule that what i need.

Edited by yucatan
Link to comment
Share on other sites

Try this:

#include <File.au3>

$PATH = InputBox("FILE","Please select path",@ScriptDir & "\file.txt")
$WORD=InputBox("WORD", "Search for word")
$FILE=FileOpen($PATH, 0)
For $INDEX = 1 To _FileCountLines($PATH)
    $LINE = FileReadLine($FILE,$INDEX)
    If StringInStr($LINE,$WORD,1) <> 0 Then Msgbox(0, "FOUND", "I found your word in line " & $INDEX)
Next
FileClose($FILE)

When the words fail... music speaks.

Link to comment
Share on other sites

hmm nice but how i can say read that file example now he found that i searched on line 2 how i can say read line 2 ?

p.s. why i cant search @ line 1 he dont find what i search on line one?

Well there are a few ways to do it one is to read and display all lines

$word=InputBox("word", "word")

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

$br=0

While 1

$l = FileReadLine($f)

If @error = -1 Then ExitLoop

MsgBox(0, "Line read:", $l)

Wend

FileClose($f)

if lines are numbered you can searc the number line instead

$word=InputBox("word", "word")

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

$br=0

While 1

$l = FileReadLine($f)

If @error = -1 Then ExitLoop

$br+=1

if stringinstr($br, $word, 1)<>0 then Msgbox(0, "found", "Contents of line " & $br)

Wend

FileClose($f)

remembering line 1 will be 0 until it runs through the first time

eg file.txt contains

Hi

Moo

Now

$br will go

$br = 0 (Hi)

$br = 1 (Moo)

$br = 2 (Now)

just trial a few ways to search and display

Link to comment
Share on other sites

Well there are a few ways to do it one is to read and display all lines

$word=InputBox("word", "word")

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

$br=0

While 1

$l = FileReadLine($f)

If @error = -1 Then ExitLoop

MsgBox(0, "Line read:", $l)

Wend

FileClose($f)

if lines are numbered you can searc the number line instead

$word=InputBox("word", "word")

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

$br=0

While 1

$l = FileReadLine($f)

If @error = -1 Then ExitLoop

$br+=1

if stringinstr($br, $word, 1)<>0 then Msgbox(0, "found", "Contents of line " & $br)

Wend

FileClose($f)

remembering line 1 will be 0 until it runs through the first time

eg file.txt contains

Hi

Moo

Now

$br will go

$br = 0 (Hi)

$br = 1 (Moo)

$br = 2 (Now)

just trial a few ways to search and display

nice nice but i only need to search for a rule containing the word i enterd and then it need to read that entire line. thats what i need..

how can i say to filereadline to read line 2 ?

Edited by yucatan
Link to comment
Share on other sites

nice nice but i only need to search for a rule containing the word i enterd and then it need to read that entire line. thats what i need..

how can i say to filereadline to read line 2 ?

FileReadLine($file,2)

When the words fail... music speaks.

Link to comment
Share on other sites

h mm okee i see i shall give it a try thx alot peopel.

just remember if you need to make it a variable you will be able to search it like in my second example

if stringinstr($br, $word, 1)<>0 then Msgbox(0, "found", "Contents of line " & $br) ; it will run till $br hits the same number

or you can just go

$word=InputBox("word", "word")

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

$l = FileReadLine($f,$word)

Msgbox(0, "found", "Contents of line " & $l)

FileClose($f)

and add inputbox to get a user typed file there are many ways to go about it

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...