#59793 - 2001-10-19 07:57 AM
Re: Realtime File Copy Progress Bar
|
Anonymous
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
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 Onfunction 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
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
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
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
1 registered
(Allen)
and 1607 anonymous users online.
|
|
|