Page 1 of 1 1
Topic Options
#59791 - 2001-10-12 07:44 PM Realtime File Copy Progress Bar
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
There seems to be a lot of interest in showing a progress bar during file copies. I have this C&D (cheap and dirty) code that will do it. It relies on the fact that a file will report a size of zero until the last byte is written. It's not a percentile graph, simply a growing row of dots.
code:

Break on

? "Please stand by whislt we copy this big file" ?
Run '%comspec% /c copy "D:\RealBig.fil" "c:\"'
While GetFileSize("C:\RealBig.fil") = 0
"."
sleep 1
loop

get $


_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#59792 - 2001-10-18 10:04 PM Re: Realtime File Copy Progress Bar
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Just had another brainstorm. With large files, one could use a program like split.exe to cut it into smaller pieces and copy them one by one, timing them and extrapolating how much longer based on results. Then you join the pieces back together with the copy command. This way you could have a reasonable prediction provided conditions don't change.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#59793 - 2001-10-19 07:57 AM Re: Realtime File Copy Progress Bar
Anonymous
Unregistered


It's too bad kix doesn't support time/date mathematics, well... without alot more kix code. If you did venture to write a function to separate the hour/minute/seconds from @time and have a bunch of files you want to copy, you could copy the 1st file and calculate the time it took to copy it, and use that estimation for the other files.. or even re-average that estimation with every file copied. Theoretically that should work well, but would require a decent ammount of code, which is why I opt for a "dumb" progress bar/status window. If you've got the time, I'd love to see that concept in action!

-Morbid

Top
#59794 - 2001-10-21 08:16 AM Re: Realtime File Copy Progress Bar
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
OK, in the grand tradition of mediocre programmers, I ripped some time calc code from @TIME (HH:MM) by cj and also some UDFs from ScriptLogic.

First, cj's:

code:

BREAK ON

? "Hit [Enter] for start time snapshot" ?
Get $
$Start = @Time
? "$$Start = " + $Start

? "Hit [Enter] for end time snapshot" $

Get $
$End = @Time
? "$$End = " + $End

; convert times to seconds.
$startsecs=val(substr($start, 1, 2))*3600 + val(substr($start, 4, 2))*60 + val(substr($start, 7, 2))
? "$$Startsecs = " + $Startsecs + " seconds from midnight" ?

$endsecs=val(substr($end, 1, 2))*3600 + val(substr($end, 4, 2))*60 + val(substr($end, 7, 2))
? "$$Endsecs = " + $Endsecs + " seconds from midnight" ?

; subtract start from end
$diffsecs=$endsecs-$startsecs
? "$$Diffsecs = " + $Diffsecs + " seconds"

; convert difference to HH:MM:SS
$hours=$diffsecs/3600
$minutes=($diffsecs-($hours*3600))/60
$seconds=($diffsecs-($hours*3600)-($minutes*60))
; convert the numbers to strings and add leading zeros if required
if $hours<10 $hours="0$hours" else $hours="$hours" endif
if $minutes<10 $minutes="0$minutes" else $minutes="$minutes" endif
if $seconds<10 $seconds="0$seconds" else $seconds="$seconds" endif

; create string
$diff=$hours+":"+$minutes+":"+$seconds
? "$$Diff = " + $Diff + " in HH:MM:SS" ?
Get $

get $


And then ScriptLogic's UDFs:

code:

Break On

function abs($Expr)
;returns the absolute value of a number
$Expr=0+$Expr
if $Expr<0
$Expr=-1*$Expr
endif
$abs=$Expr
endfunction

function Mod($dividend, $divisor)
;Modulus Function
$dividend=0+$dividend
$divisor=0+$divisor
$mod=$dividend-(($dividend/$divisor)*$divisor)
endfunction

function SerialTime($TorS)
; Syntax: SerialTime(Time | Serial)
; Where Time is a time string in HH:MM[:SS] format or
; Serial is a time serial number (seconds since midnight) 1 - 86399
; If Time is supplied, SerialTime will return the seconds since midnight.
; If seconds since midnight is supplied, SerialTime will return a time.
; DEPENDENCIES: word(), abs(), mod()
dim $Hours, $Minutes, $Seconds, $Serial, $Error
$Error = 0
if instr($TorS,":") ; Time supplied
$TorS = "" + $TorS ; Cast to string
if len($TorS) > 4 and len($TorS) < 9
$Hours = 0 + word($TorS,1,":") ; Hours as integer for calculation
if $Hours > 23 $Error = 1 endif
$Minutes = 0 + word($TorS,2,":") ; Minutes as integer for calculation
if $Minutes > 59 $Error = 1 endif
$Seconds = 0 + word($TorS,3,":") ; Seconds as integer for calculation
if $Seconds > 59 $Error = 1 endif
$Serial = ($Hours * 3600) + ($Minutes * 60) + $Seconds
if $SerialTime > 86399 $Error = 1 endif
if $Error
$SerialTime = "-1" ; Error
else
$SerialTime = "" + $Serial ; Return as string
endif
else
$SerialTime = "-1" ; Error
endif
else ; Seconds supplied
$TorS = 0 + $TorS ; Cast to integer for calculation
if $TorS <= 86399 and $TorS >= 0
$Hours = $TorS / 3600
$TorS = $TorS - ($Hours * 3600)
$Hours = "" + $Hours
$Hours = substr("00",1,2 - len($Hours)) + $Hours
$Minutes = $TorS / 60
$TorS = $TorS - ($Minutes * 60)
$Minutes = "" + $Minutes
$Minutes = substr("00",1,2 - len($Minutes)) + $Minutes
$Seconds = "" + $TorS
$Seconds = substr("00",1,2 - len($Seconds)) + $Seconds
$SerialTime = $Hours + ":" + $Minutes + ":" + $Seconds ; Return as string
else
$SerialTime = "-1" ; Error
endif
endif
endfunction

function Word($strStr, $intWrdNum, optional $strWS)
; Syntax: Word("string",number, ["white space characters"])
; Word number may be negative, in which case, words will be counted
; from the right of the string. I.e. -1 will return the last word in the string.
dim $intWrdCtr, $intLen, $intStart, $intFinish, $intStep
dim $strWord
$strStr = "" + $strStr
$intWrdNum = 0 + $intWrdNum
$strWS = "" + $strWS
$intLen = len($strStr)
$intWrdCtr = 0
if $strWS = "" ; $strWS is a string containing "white space" chars
$strWS = " ," ; Contains tab, space, comma
endif
if $intWrdNum > 0 ; Setup to parse string forward
$intStart = 1
$intFinish = $intLen
$intStep = 1
else ; Setup to parse string backward
$intStart = $intLen
$intFinish = 1
$intStep = -1
endif
if $strStr = "" or $intWrdNum = 0
$strWord = ""
else
for $intCtr = $intStart to $intFinish step $intStep
if instr($strWS,substr($strStr,$intCtr,1)) ; if whitespace
while instr($strWS,substr($strStr,$intCtr,1)) and ($intCtr <= $intLen) ; skip it
$intCtr = $intCtr + $intStep
loop
else ; if non-whitespace
$intWrdCtr = $intWrdCtr + 1 ; increment word counter
if $intWrdCtr = abs($intWrdNum) ; requires "ABS()" UDF
; If this is the correct word number, extract it to $strWrd
while not instr($strWS,substr($strStr,$intCtr,1)) and ($intCtr <= $intLen)
; Extract it in the right order!
if $intStep = 1
$strWord = $strWord + substr($strStr,$intCtr,1)
else
$strWord = substr($strStr,$intCtr,1) + $strWord
endif
$intCtr = $intCtr + $intStep
loop
else
; otherwise, skip the word
while not instr($strWS,substr($strStr,$intCtr,1)) and ($intCtr <= $intLen)
$intCtr = $intCtr + $intStep
loop
endif
endif
; "Undo" last manual increment/decrement
$intCtr = $intCtr - $intStep
next
endif
$Word = $strWord ; Return the word, if found
endfunction


? "Hit [Enter] for start time snapshot" ?
Get $
? "@@Time = " + @TIME
$Start = SerialTime(@Time)
? "$$Start = " + $Start + " seconds from midnight" ?

? "Hit [Enter] for end time snapshot" $

Get $
$End = SerialTime(@Time)
? "$$End = " + $End + " seconds from midnight" ?

? "Hit [Enter] for difference from Start to End" $
Get $

$Diff = SerialTime(Val($End) - Val($Start))
? "$$Diff = " + $Diff + " seconds"
Get $


So, with a time snapshot at the start and another one at the end, the difference can be calculated and displayed.

I guess if greater precision is needed, then @TICKS could be incorporated as well.

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#59795 - 2001-10-22 01:31 PM Re: Realtime File Copy Progress Bar
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Les,

That gives me some inspiration for my current 'semi-private' project ...

I was asked to write a script for sideways copies of some(all?) Exchange Server's databases executed on a Workstation in the Domain ... so, after stopping the relevant Exchange services I will trigger a(several?) robocopy command(s) to be executed on the Exchange Server .. (would be speed suicide to execute a copy command on the workstation , copying from server to server )

As this is a medium sized company they're in need of a self explaining / easy to use kind of script (So a progress bar would be nice)

Will try to get the intrinsic robocopy status (percentage) output visualized in the script ... maybe by parsing a copy of the logfile or something like that ... That would, if working, at least preventing 'estimation' overhead ...

Will get back to all with results !

Jochen

[ 22 October 2001: Message edited by: jpols ]

_________________________



Top
#59796 - 2001-10-24 05:52 AM Re: Realtime File Copy Progress Bar
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Jochen,
Interesting project you have on the back burner. The first thing I thought was... no way... the RoboCopy log file would hold at zero bytes until complete... I was WRONG. The log file updates incrementally so theoretically you could rip the percentages. They are quite coarse however.

I added milliseconds to the calculation for faster links or smaller files or just better precision.

code:

BREAK ON
CLS
"Hit any key for start time snapshot"
?
Get $
$Start=@Time+"."+@Ticks
"$$Start = "+$Start

; get milliseconds (actual value not significant except to subtract from $endmsecs)
$startmsecs=val(substr($start,10,Len($start)))
?
"Milliseconds to substract from end time = "+$startmsecs
?
?
"Hit any key for end time snapshot"
?
Get $
$End=@Time+"."+@Ticks
"$$End = "+$End

; get milliseconds (only net value significant)
$endmsecs=val(substr($end,10,Len($end)))
?
"Milliseconds to substract start time from = "+$endmsecs
?
?
; convert start time to seconds
$startsecs=val(substr($start, 1, 2))*3600 + val(substr($start, 4, 2))*60 + val(substr($start, 7, 2))
"$$Startsecs= "+$Startsecs+" seconds from midnight"
?
; convert end time to seconds
$endsecs=val(substr($end,1,2))*3600+val(substr($end,4,2))*60+val(substr($end,7,2))
"$$Endsecs = "+$Endsecs+" seconds from midnight"
?
; subtract start from end milliseconds
$diffmsecs=$endmsecs-$startmsecs
?
"Total $$Diffmsecs = "+$Diffmsecs+" milliseconds"

; drop the seconds (keep only the last three places)
$diffmsecs=val(substr($diffmsecs,Len($diffmsecs)-2,Len($diffmsecs)))

; subtract start from end
$diffsecs=$endsecs-$startsecs
?
"$$Diffsecs = "+$Diffsecs+" seconds"+" and "+$Diffmsecs+" milliseconds"

; convert difference to HH:MM:SS
$hours=$diffsecs/3600
$minutes=($diffsecs-($hours*3600))/60
$seconds=($diffsecs-($hours*3600)-($minutes*60))

; convert the numbers to strings and add leading zeros if required

if $hours<10
$hours="0$hours"
else
$hours="$hours"
endif

if $minutes<10
$minutes="0$minutes"
else
$minutes="$minutes"
endif

if $seconds<10
$seconds="0$seconds"
else
$seconds="$seconds"
endif

; create string
$diff=$hours+":"+$minutes+":"+$seconds
?
"$$Diff = "+$Diff+" in HH:MM:SS format"

Get $


_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#59797 - 2001-10-25 10:29 AM Re: Realtime File Copy Progress Bar
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
LLigetfa, That code you got from me was pre @ticks. half of that code is there just to get the number that @ticks returns.

cj

Top
#59798 - 2001-10-26 12:03 AM Re: Realtime File Copy Progress Bar
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Cj !!!
you're back ! Howsit goin ?

Les, ummm ... very nice indeed !!!; have you seen this yet : DeltaTime() ?
btw. I persuaded them to run this script scheduled , so need for fancy stuff ...

Jochen

_________________________



Top
#59799 - 2001-10-26 12:50 AM Re: Realtime File Copy Progress Bar
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
I am working again and using KiX at work. That excuse means I can surf da board on work time

I haven't read my ozemail for a long time now as the LAN at home is down. My other half is pregnant with baby version 2.0 and needs looking after.

I will have to do some serious coding to get the post count up, I am a fair way from top poster now

cj

Top
#59800 - 2001-10-26 12:58 AM Re: Realtime File Copy Progress Bar
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Great News !

Congrats and all that !
KiX @Work sounds good ...
Best wishes for the baby !!!

J.

_________________________



Top
#59801 - 2001-10-25 03:21 PM Re: Realtime File Copy Progress Bar
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
ceej,

Congrats my friend ... give my best to your other half and the other "little one". Does that mean your going to need another web site to host all those baby pictures you got ? (I visited your site about two days ago ... that spinning cube menu really blows my mind) ...

And it's great to see you back into "the KiXtart business" ...

-Shawn

--------------------

things frequently heard from Klingon software developers ...

"PATOCK!!!"

Top
#59802 - 2001-10-25 03:35 PM Re: Realtime File Copy Progress Bar
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
hmmm , yeah that Klingon sh*t might be a bit lame ... but hey , I like it

J.

_________________________



Top
#59803 - 2001-10-26 02:21 AM Re: Realtime File Copy Progress Bar
MCA Offline
KiX Supporter
*****

Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
Dear CJ,

Also our congratulations. Best wishes for wife and baby.

We like to see your input on the board.
greetings.

_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
#59804 - 2001-10-26 06:20 AM Re: Realtime File Copy Progress Bar
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
cj,
Congrats on the child process. About the code, you're right. I'm not claiming genius on my part... I ripped it from you. The @Ticks part wasn't in your's but all the code using it is.

Kinda lost sight of what I was doing. Started out as a KiX3 routine, but @Ticks needs KiX4, so Duh, might as well go the UDF route.

Jochen has a nice UDF "DeltaTime()" that does it with a lot less code than the ScriptLogic UDFs. Guess it depends on what other uses you may have for the UDFs.

So cj, I always wanted to know, when you pull the plug on the bathtub down under, does the water swirl clockwise or conterclockwise?

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#59805 - 2001-10-26 10:06 AM Re: Realtime File Copy Progress Bar
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
Clockwise

cj

Top
#59806 - 2001-10-26 11:06 AM Re: Realtime File Copy Progress Bar
DrillSergeant Offline
MM club member
*****

Registered: 2004-07-09
Posts: 1164
Loc: Eijsden, the Netherlands
Hi CJ,

Best wishes for you, your wife and your 1.2 kids

I also need to get my post count up , so I'm looking for a nice challenge to work on.

BTW have you seen this post? it's based on your 2D arrays:
http://kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=2&t=002373

_________________________
The Code is out there

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1452 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.049 seconds in which 0.021 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org