Sign in to follow this  
Followers 0
DCCD

Progressbar, FileReadLine

5 posts in this topic

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)

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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!"

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

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