Jump to content

ProgressBar for FileCopy with FileGetSize and Percent level


DigDeep
 Share

Recommended Posts

I have code for getting ProgressBar with InetGetSize and Percentage completed for getting files downloaded from browser.

But I need the same when attempting to download the file using FileCopy.

Can someone help me in arranging the While section here please?

 

Note: The commands inside While statements will be looking incorrect here...

#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global $iPlaces

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 1538, 895, 192, 124)
$Button1 = GUICtrlCreateButton("Get File", 1056, 512, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Button1
            FileDown() ; Download file
    EndSwitch
WEnd


Func _Get_Display_Size($iTotalFileDownloaded, Const $iPlaces) ; Get file size
    Local Static $aSize[4] = ["Bytes", "KB", "MB", "GB"]
    For $a = 0 To 3
        $iTotalFileDownloaded /= 1024
        If (Int($iTotalFileDownloaded) = 0) Then Return Round($iTotalFileDownloaded * 1024, $iPlaces) & " " & $aSize[$a]
    Next
EndFunc   ;==>_Get_Display_Size

Func FileDown() ; Download file
    Local $Lable1 = GUICtrlCreateLabel("Downloading file...", 274 , 460 , 645 , 55)
    Local $Progress = GUICtrlCreateProgress(446 , 540 , 300 , 20 , $PBS_SMOOTH)
    $FileSize = GUICtrlCreateLabel("", 448 , 565 , 200 , 20)
    $Percent = GUICtrlCreateLabel("", 450 , 590 , 106 , 20)

    Local $src = @MyDocumentsDir & '\TestFile.exe'
    Local $dest = 'c:\Temp\TestFile.exe'
    $FileCopy = FileCopy($src, $dest, 1)
    $FileCopy_SrcSize = FileGetSize($src)

; =============>>>>>>>>>>> Need help with this section <<<<<<<<<<==============

    While Not InetGetInfo($FileCopy, 2) ;Loop until download is finished
        Sleep(100) ;Sleep for half a second to avoid flicker in the progress bar
        $GetDownBytes = InetGetInfo($FileCopy, 0) ;Get bytes received
        $GetDownPercent = Int($GetDownBytes / $FileCopy_SrcSize * 100) ;Calculate percentage
        $Totalsize = $FileCopy_SrcSize - $GetDownBytes
        GUICtrlSetData($Progress, $GetDownPercent)
        GUICtrlSetData($FileSize, _Get_Display_Size($Totalsize, $iPlaces = 2) & ' remaining...')
        GUICtrlSetData($Percent, $GetDownPercent & " % completed")
        Sleep(100)
    WEnd

; =============>>>>>>>>>>> Need help with this section <<<<<<<<<<==============
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...