Jump to content

copy progress with estimated time


myk3
 Share

Recommended Posts

I have seen a bunch of progress bars associated with copy a file/directory.. I am in need of one with an estimated time..

the best one imo is the one copied below, basically using the native copy / paste from windows. However i would like to remove the gui styles and the cancel button. I don't think I can do this with the native command. Any ideas?

func _FileCopy($fromFile, $tofile)
    Local $FOF_RESPOND_YES = 16
    Local $FOF_SIMPLEPROGRESS = 256
    $winShell = ObjCreate("shell.application")
    $winShell.namespace($tofile).CopyHere($fromFile, $FOF_RESPOND_YES)
EndFunc
Link to comment
Share on other sites

Have a look at this UDF by Yashied >>

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Have a look at this UDF by Yashied >>

I have actually used that and modified it to my liking.. however it doesn't give back an estimate time.. it does give a % left, but not an estimated time..

I know the time is in microsoft minutes, which mean absolutely nothing, but i would like consistency in the entire script.. with everything estimating time.. If i cant find anything i might just block input and unblockit once the copy is finished..

Edited by myk3
Link to comment
Share on other sites

Just took a cursory look at Copy UDF. It would be a bit messy but it seems like you could do the calculations if you apply the percentages to each file, get the file size for each, start time etc..

The file copy is going to be slow compared to CPU usage so doing a bunch of calculations should be negligible. Updating the GUi without lag may the the hardest part.

Link to comment
Share on other sites

Just took a cursory look at Copy UDF. It would be a bit messy but it seems like you could do the calculations if you apply the percentages to each file, get the file size for each, start time etc..

The file copy is going to be slow compared to CPU usage so doing a bunch of calculations should be negligible. Updating the GUi without lag may the the hardest part.

i'm not sure how i would guesstimate the end time?

Here is the function i am currently using to copy the items.. it is basically a bastardized of the copy.udf example 1.

Func _copy($source,$Destination,$span)
ProgressOn("Copy Span...", "Copying Span "& $span)
_Copy_CopyFile($Source, $Destination)
Do
    Sleep(250)
    $State = _Copy_GetState()
ProgressSet(StringFormat('%.f%', $State[1] / $State[2] * 100),StringFormat('%.f%', $State[1] / $State[2] * 100))
Until Not $State[0]
ProgressOff()
EndFunc
Edited by myk3
Link to comment
Share on other sites

I have not seen that UDF but I'm guessing $State[1] is the file size and $State[2] is the amount copied.

Since you are checking every 250 ms, you do a calculation on how much you have downloaded in that time

Tally that against the file size with some maths voodoo to a guestimate.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

I have not seen that UDF but I'm guessing $State[1] is the file size and $State[2] is the amount copied.

Since you are checking every 250 ms, you do a calculation on how much you have downloaded in that time

Tally that against the file size with some maths voodoo to a guestimate.

from looking at the UDF the states are as follows..

;                           [0] - The current state. (0 - Complete; (-1) - Prepare; 1 - Progress)
;                           [1] - Total bytes transferred.
;                           [2] - Total size, in bytes.
;                           [3] - The current file's bytes transferred.
;                           [4] - File size, in bytes.
;                           [5] - System error code. (0 - No error; (-1) - Internal DLL error; * - System error (see MSDN))
;                           [6] - The full path to the source file that in progress.
;                           [7] - The full path to the destination file that in progress.
Link to comment
Share on other sites

If x percent is completed for file z then (current time - start time) / x should equal the time for each percentage transfer. Percent remaining times this factor should give time remaining. Just make sure you don't divide by zero :)

I think i almost got it.. only problem now is the output..the time is accurate.. but it is like the output is in total seconds.. since when the digit to the left of the decimal is at 0 the numbers to the right are the seconds.. so i think it is outputting total seconds remaining..

1% 12.8699999999999
1% 12.8699999999999
1% 12.8699999999999
2% 6.36999999999995
2% 6.36999999999995
2% 6.36999999999995
2% 6.36999999999995
2% 6.36999999999995
2% 6.36999999999995
2% 6.36999999999995
3% 4.2033333333333
3% 4.2033333333333
3% 4.2033333333333
3% 4.2033333333333
3% 4.2033333333333

here is the current code

Func _copyswms($source,$Destination,$span)
ProgressOn("Copy Span...", "Copying Span "& $span)
_Copy_CopyFile($Source, $Destination)
$starttime = @HOUR & "." & @MIN & "." & @SEC
Do
    Sleep(250)
    $State = _Copy_GetState()
    $percomplete =StringFormat('%.f%', $State[1] / $State[2] * 100) ;x
    $perremain = 100 - $percomplete
    $currenttime =  _NowTime(5)
    $timepercent =($currenttime - $starttime) / $percomplete
;~     ProgressSet($percomplete,$perremain * $timepercent)
    $timeremain = StringTrimLeft($perremain * $timepercent,1)
    $timeremain = StringReplace ($timeremain,".","")
    $timeremain = StringLeft($timeremain,4)
    ConsoleWrite ( $percomplete & " " & $timeremain & @crlf)
Until Not $State[0]
ProgressOff()
EndFunc
Edited by myk3
Link to comment
Share on other sites

For what your doing I would use the TimerDiff() function over the time macros. Easiest way I found is to first calculate your current rate, then calculate finish time based on that rate. This should work:

Func _copyswms($source,$Destination,$span)
ProgressOn("Copy Span...", "Copying Span "& $span)
_Copy_CopyFile($Source, $Destination)
$starttime = TimerInit()
Do
    Sleep(250)
    $State = _Copy_GetState()
    $percomplete = ($State[1] / $State[2]) * 100 ;x
    $iCurrent_Rate = $State[1] / TimerDiff($starttime) ; speed of transfer (bytes/ms)
    $ibytes_remaining = $State[2] - $State[1]
    $iTime_MS_Remaining = Int($ibytes_remaining / $iCurrent_Rate)
    ConsoleWrite ( $percomplete & " " & $iTime_MS_Remaining & @crlf)
Until Not $State[0]
ProgressOff()
EndFunc
Link to comment
Share on other sites

For what your doing I would use the TimerDiff() function over the time macros. Easiest way I found is to first calculate your current rate, then calculate finish time based on that rate. This should work:

Func _copyswms($source,$Destination,$span)
ProgressOn("Copy Span...", "Copying Span "& $span)
_Copy_CopyFile($Source, $Destination)
$starttime = TimerInit()
Do
    Sleep(250)
    $State = _Copy_GetState()
    $percomplete = ($State[1] / $State[2]) * 100 ;x
    $iCurrent_Rate = $State[1] / TimerDiff($starttime) ; speed of transfer (bytes/ms)
    $ibytes_remaining = $State[2] - $State[1]
    $iTime_MS_Remaining = Int($ibytes_remaining / $iCurrent_Rate)
    ConsoleWrite ( $percomplete & " " & $iTime_MS_Remaining & @crlf)
Until Not $State[0]
ProgressOff()
EndFunc

so I do I convert "$iTime_MS_Remaining" to actual mins?
Link to comment
Share on other sites

so I do I convert "$iTime_MS_Remaining" to actual mins?

Not sure I follow. Do you have to convert? No. But If you want to display the Msec as minutes, then yes you will need to convert them to minutes.

Link to comment
Share on other sites

myk3, I usually express this like

Local $iTime_MS_Remaining = TimerInit() 
Sleep(2000) 
consolewrite(round(timerdiff($iTime_MS_Remaining)/1000,2) & @lf)

Gives seconds to 2 places.

kylomas

edit: formatting

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

You can also look at function _TicksToTime(). It converts ms to Hours, minutes ,sec.

Link to comment
Share on other sites

This seems to work well

Func _copyswms($source,$Destination,$span)
ProgressOn("Copy Span...", "Copying Span "& $span)
_Copy_CopyFile($Source, $Destination)
$starttime = TimerInit()
Do
    Sleep(250)
    $State = _Copy_GetState()
    $percomplete = ($State[1] / $State[2]) * 100 ;x
    $iCurrent_Rate = $State[1] / TimerDiff($starttime) ; speed of transfer (bytes/ms)
    $ibytes_remaining = $State[2] - $State[1]
    $iTime_MS_Remaining = Int($ibytes_remaining / $iCurrent_Rate)
$FormattedTime =  _TimeReadable($iTime_MS_Remaining)
ProgressSet($percomplete,stringleft($percomplete,2)& "%" & "   " & $FormattedTime & " Time Remaining")
    ConsoleWrite ( $percomplete & " " & $FormattedTime & @crlf)
Until Not $State[0]
ProgressOff()
EndFunc

Func _TimeReadable($mili)
    $TotalSeconds = Int($mili / 1000); convert miliseconds to seconds
    $Hours = Int($TotalSeconds / 3600); 3600 seconds in an hour
    $Minutes = Int(($TotalSeconds - ($Hours * 3600)) / 60); 60 secs per min
    $Seconds = $TotalSeconds - (($Hours * 3600) + ($Minutes * 60)); leftovers
    If $Hours < 10 Then $Hours = "0" & $Hours
    If $Minutes < 10 Then $Minutes = "0" & $Minutes
    If $Seconds < 10 Then $Seconds = "0" & $Seconds
    $FormattedTime = $Minutes & ":" & $Seconds
    Return $FormattedTime
EndFunc  ;==>_TimeReadable
Link to comment
Share on other sites

This appears to just give the time since the last check.. am i wrong?

Yes, It gives the amount of time that has passed since _Timerint() was called. _Timereadable() does pretty much the same thing as _TickstoTime().
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...