Jump to content

FileGetSize not working after 2nd use


jsteng
 Share

Recommended Posts

I have a running program that continuously write to a text file.

My requirement is to have an AutoIt script that constantly fetches this text file's filesize using FileGetSize($logfile) in a loop.

All seems working. However, I noticed that FileGetSize is not getting updated at all. It remains constant all throughout.

What gives? AutoIt's script is running in admin mode.

Is there something I need to do in order refresh this FileGetSize function?

 

FYI: Someone else asked this back in 2013 with no answer to his question. Maybe newer Autoit has an answer?

 

Thanks.

 

 

Link to comment
Share on other sites

  • Moderators
7 minutes ago, jsteng said:

What gives?

@jsteng this is like telling your mechanic your car is making a strange noise "somewhere" and asking him to diagnose it over the phone. Please read this post to see how to ask decent questions on the forum:

https://www.autoitscript.com/forum/topic/110993-faq-updated-please-read-before-posting/?do=findComment&comment=1405467

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

#RequireAdmin

If Not IsAdmin() Then
    If @error Then Return MsgBox(16 + 262144, "ERROR!", "Requires to run as Admin.")
    Exit
EndIf

Global $logfile    = @MyDocumentsDir & "\udit\logs\logs.txt"
Global $sLine    = ""
Global $lFile    = FileOpen($logfile)
Global $logSize    = 0
FileSetPos($lFile, 0, 2) ;sets the current read position to the end of the file

while 1
    $logsize = FileGetSize($logfile)
    $sLine = FileReadLine($lFile)
    ToolTip( stringformat("%8d %s", $logsize,$sLine), @DesktopWidth/2, @DesktopHeight-12,"",0,2)
    sleep(100)
wend

 

Said log/text file is not static; it is constantly getting written, about 1-10x per second. And the ToolTip line was printing the new lines written into it but the FileGetSize isnot getting updated.

Edited by jsteng
Link to comment
Share on other sites

Sample script that creates log file:
 

#RequireAdmin
#include <Date.au3>

If Not IsAdmin() Then
    If @error Then Return MsgBox(16 + 262144, "ERROR!", "Requires to run as Admin.")
    Exit
EndIf

Global $logfile    = @MyDocumentsDir & "\udit\logs\logs.txt"
Global $sLine    = ""
Global $lFile    = FileOpen($logfile,1)
Global $logSize    = 0
FileSetPos($lFile, 0, 2) ;sets the current read position to the end of the file

while 1
    FileWrite($lFile, _NowCalc() & '.' & @MSEC & @CRLF)
    sleep(300)
wend

 

Link to comment
Share on other sites

Have you tried closing the file after all the writing is done then checking the size again?

For some reason I can't insert code...

While 1
FileOpen
FileWrite
FileClose
FileGetSize
WEnd

Edited by IAMK
Link to comment
Share on other sites

Try something like:

#include <Date.au3>
#include <WinAPIFiles.au3>

Global $sLogFile    = @ScriptDir & "\udit\logs\logs.txt"
If FileExists($sLogFile) = 0 Then _LogCreate()

AdlibRegister("_LogStatus")

While 1
    FileWrite($sLogFile, _NowCalc() & '.' & @MSEC & @CRLF)
Wend

Func _LogStatus()
    Local $iLogSize = FileGetSize($sLogFile)
    Local $sLogLine = FileReadLine($sLogFile, -1)
    ToolTip(StringFormat("%8d %s", $iLogSize, $sLogLine), @DesktopWidth/2, @DesktopHeight-12, "" ,0,2)
EndFunc

Func _LogCreate()
    Local $hLogFile = FileOpen($sLogFile, 9)
    FileClose($hLogFile)
EndFunc

 

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