Jump to content

Progressbar, FileReadLine


Recommended Posts

this works, but "fileReadLine" finish before "progress bar" Any idea how to fix this?

#include <GUIConstants.au3>

$Source      = "C:\20080426(002).data";1Gb!
$total       = FileGetSize($Source)
$F           = FileOpen($Source, 0)
$count       = 0
$GUI         = GUICreate("GUI",400,60,-1,-1)
$GUIProgress = GUICtrlCreateProgress (10,10,380,40)
GUISetState (@SW_SHOW)

while 1
    $line = FileReadLine($F)
    If @error    = -1 Then ExitLoop
    $count       = $count + StringLen($line)
    $iPercentage = Round(($count/$total)*100)
    GUICtrlSetData($GUIProgress, $iPercentage)
WEnd

FileClose($F)
Link to comment
Share on other sites

this works, but "fileReadLine" finish before "progress bar" Any idea how to fix this?

#include <GUIConstants.au3>

$Source      = "C:\20080426(002).data";1Gb!
$total       = FileGetSize($Source)
$F           = FileOpen($Source, 0)
$count       = 0
$GUI         = GUICreate("GUI",400,60,-1,-1)
$GUIProgress = GUICtrlCreateProgress (10,10,380,40)
GUISetState (@SW_SHOW)

while 1
    $line = FileReadLine($F)
    If @error    = -1 Then ExitLoop
    $count       = $count + StringLen($line)
    $iPercentage = Round(($count/$total)*100)
    GUICtrlSetData($GUIProgress, $iPercentage)
WEnd

FileClose($F)

You must take into account the @CRLF.
Link to comment
Share on other sites

FileGetSize is not a good way to actually get the what you are looking for since FileReadLine() strips @CR & @LF.

This function isn't tested but it should be pretty close.

$Total = _StringSize($Source)

Func _StringSize($sStr)
    If FileExists($sStr) Then $sStr = FileRead($sStr)
    Local $iSize = StringLen(StringReplace(StringStripCR($sStr)), @LF, "")
    Return $iSize
EndFunc

Another way would be this

$Total = _StringSize($Source)

Func _StringSize($sStr)
    If FileExists($sStr) Then $sStr = FileRead($sStr)
    StringRegExpReplace($sStr, "\V", "")
    Local $iSize = @Extended
    Return $iSize
EndFunc
Edited by GEOSoft

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

Strange, even taking line feeds into account I didn't came nearly anywhere the real filesize. Anyway, filereadline() is quiet slow. Is it really necessary, esp. parsing a 1GB file?

#include <GUIConstants.au3>

$Source      = "C:\20080426(002).data" ;1Gb!
$total       = FileGetSize($Source)
$F           = FileOpen($Source, 0)
$count       = 0
$GUI         = GUICreate("GUI",400,60,-1,-1)
$GUIProgress = GUICtrlCreateProgress (10,10,380,40)
GUISetState (@SW_SHOW)

$BufferSize = 1024 * 10 ; 10kb

For $i = 1 To Ceiling($total / $BufferSize)
    $line = FileRead($F, $BufferSize)
    $count       += $BufferSize
    $iPercentage = Round(($count/$total)*100)
    GUICtrlSetData($GUIProgress, $iPercentage)
Next

FileClose($F)
Edited by KaFu
Link to comment
Share on other sites

@GEOSoft, Thanks "both" function works, but with small files!, fails reading 1GB file, see attached pic! My files between 1GB and 4GB.

@KaFu, Thank you so much, WORKS 100%, but takes forever!!!

post-30451-12476455776842_thumb.jpg

Edited by DCCD
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...