RazorTorque4X Posted March 1, 2010 Share Posted March 1, 2010 So, I tried to find a way to find copy rate, that is how fast are files being copied when using FileCopy(), what I thought was that to start a TimerInit() before coping and then in a loop get the size of file in destination and by TimerDiff() find the difference and then divide the size by that difference to get the rate. But there were errors Here is the code what I tried #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> GUICreate("copier", 250, 250, Default, Default) $copy = GUICtrlCreateButton("copy", Default, Default, 80, 40) $label = GUICtrlCreateLabel("copy rate", 20, 50, 80, 20) Dim $time GUISetState() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $copy $time = TimerInit() ;start the timer FileCopy("F:\Games\RESIDENT EVIL 5.zip", "C:\RE\", 9) ;start copying Do $size = FileGetSize("C:\RE\RESIDENT EVIL 5.zip") / (1024 * 1024) ;find the size of file at destination in Mb $TimeEnd = TimerDiff($time) ;stop the timer $rate = $size / ($TimeEnd / 1000) ;rate in Mb per sec GUICtrlSetData($label, $rate) ;update the label Until FileGetSize("C:\RE\RESIDENT EVIL 5.zip") / (1024 * 1024 * 1024) >= 4.2 ;until the whole game of 4.2Gb is copied Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd But I think the script doesn't returns from the FileCopy() until whole file is copied, so as to go in the Do loop and update the label. Also I stopped the execution after 10 sec to see the file in C:\RE and when I checked the properties it said "4.2 Gb" but it was not the full game, as when I tried to extract it all (winrar, 7zip, and windows default zip viewer) reported error that archieved in corrupted. Which means the files wasn't fully copied. So can any one point out what am I doing wrong in here? Link to comment Share on other sites More sharing options...
99ojo Posted March 1, 2010 Share Posted March 1, 2010 (edited) Hi, the problem is, that file space is allocated at once, so FileGetSize will fail. I did the trick with robocopy.exe from Windows2003 Ressource Kit from Microsoft. You have to download. #include <Constants.au3> #include <GUIConstantsEx.au3> $source = "F:\Games" $copyfile = "RESIDENT EVIL 5.zip" $size = Round (FileGetSize ($source & "\" & $copyfile) / 1024 / 1024, 1) $target = "C:\RE" GUICreate("copier", 250, 250, Default, Default) $copy = GUICtrlCreateButton("copy", Default, Default, 80, 40) GUISetState() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $copy $label = ProgressOn ("Copy State", "Copied") $pid = Run (@ComSpec & " /c " & "robocopy " & Chr (34) & $source & Chr (34) & " " & Chr (34) & $target & Chr (34) & " " & $copyfile & " /S /E", "", @SW_HIDE, $STDOUT_CHILD) $oldvalue = 0 While 1 sleep (1000) $line = StdoutRead($pid) If @error Then ExitLoop $newvalue = Round (Number (StringTrimRight ($line, 1)) * $size / 100, 1) ProgressSet ($line, $copyfile & " " & $newvalue & " MB " & "from " & $size & " MB copied." & @CRLF & "Throughput: " & Round ($nvalue - $ovalue, 1) & " MB / s") $oldvalue = $newvalue Wend ProgressOff () Exit Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd ;-)) Stefan @Edit: Added Throughput Edited March 1, 2010 by 99ojo Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now