Jump to content

Fileread?


Recommended Posts

Dude, if you keep asking for people to write your scripts you won't learn. Read the help files, read the FAQs on this site and try a couple of things. This is like your third post asking for people to do your work for you.

You can't see a rainbow without first experiencing the rain.

Link to comment
Share on other sites

  • Developers

hi i wanne make a script thats read a notepad document and if on the first rule is "" then ........ else .......

how do i need to make it i cant figure it out:S

help me pleas

zucht, wat was er zo moeilijk aan mijn antwoord in een van je vele vorige vragen.

Stop met het afvuren van nieuwe vragen totdat je ZELF eerst een poging doet om het ZELF te maken.

Edited by Jos

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

hi i'm trying to read a file and then compare it can somebody tell me what i'm doing wrong?

$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

$chars = FileRead($file, 1)

If StringinStr($chars,"test") = 1

Then msgBox(4096, "ERREUR!", "er staat test")

Else msgBox(4096, "ERREUR!", "anders")

EndIf

Link to comment
Share on other sites

hi can somebody tell me why i get error's what i'm doing wrong in string compare?

$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

$chars = FileRead($file, 1)

if StringCompare ("$chars", "test" [, 0]) = 0 Then

MsgBox(0, "er staat test")

Else

MsgBox(0, "anders")

EndIf

Link to comment
Share on other sites

  • Developers

hmm i dont know why jos is whining again but i did try it and i did searched but i realy cant find it i thout that a forum is for when you haveing problems with things....

I am not and if you would have bothered to look at the details you could have concluded that I merged the 2 Threads.

So next time think before making stupid smart remarks.

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

  • Developers

OK, now I am going to do a bit more whining:

Stop creating new topic about the same issue!

Next time they will be simply locked.

I have merged them again.

Edited by Jos

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

When you see the square bracket used in the help file it indicates an option. They should not be included in the line.

if StringCompare ($chars, "test" , 0) = 0

In the case of StringCompare, 0 is the default so it's not required at all. The line above is the same as

if StringCompare ($chars, "test") = 0

On top of all that I have a hunch that what you are looking for is more along the lines of StringInStr()

If StringInStr($chars, "test") Then

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

hi

i have tryid it with If StringInStr($chars, "test") Then but when i use Else then i get syntax error's why is that

and he always say there is not standing test but i'm sure that in that document is writen test.... how is this possebel ?

FileChangeDir (@DesktopDir)

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

$chars = FileRead($file, 1)

if StringCompare ($chars, "test") = 0 Then MsgBox(0, "Error", "er staat test")

this is the code now

i'm sure that in test.bat is standing test but it dont say er staat test

why it dont work i just am searching and searching i cant find it:(

Edited by yucatan
Link to comment
Share on other sites

You cannot put statements on the same line as "Else" as to why you are getting a syntax error.

This example may help you to understand.

; Check that working directory changes to @DesktopDir
If FileChangeDir(@DesktopDir) Then
    ; Open a file handle for read
    $handle = FileOpen('test.bat', 0)
    ; Check if the handle is valid
    If $handle <> -1 Then
        ; Read the complete file
        $text = FileRead($handle)
        ; Find "test" with $text
        if StringInStr($text, "test") Then
            ; Show Msgbox if StringInStr returns not 0
            MsgBox(0, '', '"test" found')
        Else
            ; Show Msgbox if StringInStr returns 0
            MsgBox(0, '', '"test" not found')
        EndIf
        ; Close the file handle
        FileClose($handle)
    EndIf
EndIf

Have a look in the help file contents for "If...ElseIf...Else...EndIf" for syntax that is valid.

:D

Link to comment
Share on other sites

yoo have to do a loop, for read all the document, it can be like this:

While 1
$LineRead = FileReadLine($file)
            If @error = -1 Then ExitLoop
            $array = StringSplit($LineRead, ";")
            If $Variable = $array[1] then; put the position you want to compare
                                                 [conditions]
                                                  endif

Wend

don't forget to open the file first, in a read mode.

Link to comment
Share on other sites

You are aware that FileReadLine() is the slowest possible method of reading a file, are you not? Better to read the file to an array than to do that.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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