Sign in to follow this  
Followers 0
Pera

FileRead() and Flieclose() Help...

12 posts in this topic

I have a code that contains the following;

[/autoit]
Global $file

While 1

$file = FileOpen("Filepath\chat.log")

$TexttobeRead = $file

.
.
.
.
.

Func DeleteLog()

FileClose($file)
$file = FileOpen( "Filepath\chat.log", 2)    ;to erase the previous content
FileClose($file)

EndFunc
[autoit]

For some reason even though chat.log file is being erased by DeleteLog function, I still get an error saying that "Maximum number of lines can be opened is reached". That is not the exact error but its close to that. Pretty much i am getting error that makes me believe that somewhere somehow $file is keep building up, even though the chat.log file is getting erased periodically.

Any help would be greatly appreciated.

Thanks

Share this post


Link to post
Share on other sites



can you show an actual scriptlet that shows the behaviour ?

Sounds to me you are foing more fileOpen() statements than FileClose() statements...


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

#4 ·  Posted (edited)

nah... that was another issue so my guess is that the script is changed and the FileOpen() is now at the wrong spot ... :D

...but yes... that topic should have been used ... its now very confusing

Edited by JdeB

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

#5 ·  Posted (edited)

I changed that script since I post. I figured out that the reason why things got messed up in that script because I assign the chat.log to $file at the very beginning and never again. So I moved the assignment "$file = FileOpen(FilePath\chat.log)" Inside the loop.

Edited by Pera

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Ok looks like I got it, but not sure I can't try it right now. My script looked like this when the error happened;

[/autoit]
Global $file

While 1

$file = FileOpen("Filepath\chat.log")

$TexttobeRead = $file

.
.
.
.
.

Func DeleteLog()

FileClose($file)
$file = FileOpen( "Filepath\chat.log", 2)    ;to erase the previous content
FileClose($file)
$file = FileOpen( "Filepath\chat.log", 0)   ;I believe this is the reason??

EndFunc
[autoit]

So I think what happened is I opened the file once in the loop, closed it in the DeleteLog() func, opened it, and opened it again in the loop. So eventually I kept opening the file over and ovr without closing it.

I apoligize I post a lot in the last couple of days but I just start using AutoIt recently (3-4 days ago) and still trying to figure things out.

Thanks!

Edited by Pera

Share this post


Link to post
Share on other sites

The question is...do you need to have a handle to the file or just use FileRead to read the whole file and just use FileDelete on it to clear as the program would recreate the log file again?

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

The question is...do you need to have a handle to the file or just use FileRead to read the whole file and just use FileDelete on it to clear as the program would recreate the log file again?

Hmm... I think you are right I could just FileRead() and when my requirements are met I could FileDelete(). But wouldn't the script error out if it tried to read the chat.log again before the program creates it?

Edit: I misread your post

Edited by Pera

Share this post


Link to post
Share on other sites

My thoughts are that FileOpen and FileClose are not needed if you just want to use FileRead to read the whole file once and a while. FileOpen is useful when you are constantly reading or writing to a file by using a handle but you use adequate sleeps that using a handle is perhaps not a speed issue so it maybe easier to not use FileOpen/FileClose and the handle they open and close?

Share this post


Link to post
Share on other sites

My thoughts are that FileOpen and FileClose are not needed if you just want to use FileRead to read the whole file once and a while. FileOpen is useful when you are constantly reading or writing to a file by using a handle but you use adequate sleeps that using a handle is perhaps not a speed issue so it maybe easier to not use FileOpen/FileClose and the handle they open and close?

Alright then, how about something like this;

[/autoit]
While 1 


Mouseclick("Right", 725, 480, 1)

$TexttobeRead = FileRead("FilePath\chat.log") 
;MsgBox(0, "Outside the BG", $TexttobeRead, 10) 

If StringInStr($TexttobeRead, "entering") Then 

;MsgBox(0, "Inside the BG", "We are Inside the BG", 10) 
    Sleep(Random(750, 900)) 
    Send("{LCTRL 2}") 
Send("{g}") 
InsideBG() 
DeleteLog() 
EndIf 

;MsgBox(0, "Waiting to Enter the BG","", 10) 
Sleep(Random(300, 450)) 

Wend 

Func DeleteLog() 

FileDelete("FilePath\chat.log")
EndFunc 

Func InsideBG() 

Do 

Send("{TAB}") 
Sleep(random(2000, 4000)) 
Send("{TAB}") 
Sleep(random(2000, 4000)) 
Send("{TAB}") 
Sleep(random(2000, 4000)) 
Send("{TAB}") 
Sleep(random(2000, 4000)) 

$InsideBGCheck = FileRead("FilePath\chat.log") 
;MsgBox(0, "Inside BG Function", $InsideBGCheck, 10) 

Sleep(Random(3000, 6000)) 

Send("{LCTRL 2}") 
Send("{g}") 

Until StringInStr($InsideBGCheck, "ended") 

EndFunc 
[autoit]

Share this post


Link to post
Share on other sites

Looks worth trying. :)

Tip: Don't set clicks parameter for MouseClick as 1 is default setting and is a optional parameter.

Share this post


Link to post
Share on other sites

Looks worth trying. :D

Tip: Don't set clicks parameter for MouseClick as 1 is default setting and is a optional parameter.

I know its a very ugly looking code :).

thanks for the tip.

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