Sign in to follow this  
Followers 0
parkball2

Copy With Progress Bar

2 posts in this topic

Heres another one. Very simple.

Copies a directory into another even if the destination does not exist. Progress bar shows percentage copied and time remaining until complete.

FOR OVERWRITING FILES: The copy portion will work fine (will overwrite files depending on XCOPY switch) but the progress bar may show erroneous percentages and times (depending on the amount (size) being overwritten).

DOES NOT create a log of files not copied.

Play around with it. I'm a noob, comments wil be appreciated.

J

; Define Source and Destination Directories

$source = "C:\sourcedir\"   
$dest = "c:\destination\"   

; Obtain Source and Destination Directories' sizes

$ssize =  DirGetSize($source)
$dsize = DirGetSize($dest)

; Removes "-1" return if the destination directory does not exist

if $dsize < 0 then
    $dsize = 0
Endif

; Begins the timer and XCOPY to copy files (will overwrite, remove /y switch to not overwirte)

$tbegin = TimerInit()
Run(@ComSpec & " /c xcopy /y /e " & $source & "*.* " & $dest, "", @SW_HIDE) 

; Begins Progress Bar and sets it to 0

ProgressOn("Copying Files ...", "", "0 %")
ProgressSet(0, "Calculating transfer time...")
sleep(2000); so that erroneous times are not calculated during xcopy startup

For $percent = 0 to 100 

    $copied = DirGetSize($dest) - $dsize      ; calculates how much has been copied
    $percent = Round(($copied/$ssize),2) * 100; percentage copied
    $tdiff = TimerDiff($tbegin)           ; time difference since copy began
    $tmin = Round(((100/$percent) -1) * ($tdiff/60000))  ; time (in minutes) to completion
    $tsec = Round(((100/$percent) -1)* ($tdiff/1000))   ; tims (in secs) to completion
    
; If the time remaining is less than 1 minute the progress bar will show time remaining in secs

    If $tsec < 60 then
        $tdisplay = "Approximately " & $tsec & " second(s) remaining"
    Else
        $tdisplay = "Approximately " & $tmin & " minute(s) remaining."
    Endif   
    ProgressSet( $percent, "Percentage Copied: " & $percent & " %" & @LF_
                & $tdisplay)
    sleep(1000)
Next
ProgressSet(100 , "Complete", "")
sleep(1500)
ProgressOff()

Share this post


Link to post
Share on other sites



Heres another one. Very simple.

Copies a directory into another even if the destination does not exist. Progress bar shows percentage copied and time remaining until complete.

FOR OVERWRITING FILES: The copy portion will work fine (will overwrite files depending on XCOPY switch) but the progress bar may show erroneous percentages and times (depending on the amount (size) being overwritten).

DOES NOT create a log of files not copied.

Play around with it. I'm a noob, comments wil be appreciated.

.......

Hello.

An intersting work, but for educationnal purpose only : performance will be poor because, dirgetsize have to scan the source and destination directories : so the source directory will be scanned twice : first time to evaluate size, second time to realy copy files.

[edit] : I reread you script : it's worse than i expected : your script use dirgetsize every second on destination directory !! Performance will dramaticaly slowdown!.

[edit bis] : another conception failure : when you initiate a loop (for $percent in 0 to 100), you should NEVER recalculate $percent inside the loop..

Either your loop pass through the 100 differents values of $percent , and you have to calculate the time you have to sleep inside the loop so you will match the time xcopy is working

Or you have to begin a loop with conditionnal statement (while $percent < 100 )...

well well, you have still to work your programation method, but this is a nice goal :o

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