myk3 Posted January 5, 2012 Share Posted January 5, 2012 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 More sharing options...
guinness Posted January 5, 2012 Share Posted January 5, 2012 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 parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
myk3 Posted January 5, 2012 Author Share Posted January 5, 2012 (edited) 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 January 5, 2012 by myk3 Link to comment Share on other sites More sharing options...
MilesAhead Posted January 5, 2012 Share Posted January 5, 2012 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. My Freeware Page Link to comment Share on other sites More sharing options...
myk3 Posted January 5, 2012 Author Share Posted January 5, 2012 (edited) 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 January 5, 2012 by myk3 Link to comment Share on other sites More sharing options...
JohnOne Posted January 5, 2012 Share Posted January 5, 2012 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 More sharing options...
MilesAhead Posted January 5, 2012 Share Posted January 5, 2012 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 My Freeware Page Link to comment Share on other sites More sharing options...
myk3 Posted January 7, 2012 Author Share Posted January 7, 2012 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 More sharing options...
myk3 Posted January 7, 2012 Author Share Posted January 7, 2012 (edited) 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 January 7, 2012 by myk3 Link to comment Share on other sites More sharing options...
Beege Posted January 7, 2012 Share Posted January 7, 2012 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 meoit 1 Assembly Code: fasmg . fasm . BmpSearch . Au3 Syntax Highlighter . Bounce Multithreading Example . IDispatchASMUDFs: Explorer Frame . ITaskBarList . Scrolling Line Graph . Tray Icon Bar Graph . Explorer Listview . Wiimote . WinSnap . Flicker Free Labels . iTunesPrograms: Ftp Explorer . Snipster . Network Meter . Resistance Calculator Link to comment Share on other sites More sharing options...
myk3 Posted January 7, 2012 Author Share Posted January 7, 2012 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 More sharing options...
Beege Posted January 8, 2012 Share Posted January 8, 2012 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. Assembly Code: fasmg . fasm . BmpSearch . Au3 Syntax Highlighter . Bounce Multithreading Example . IDispatchASMUDFs: Explorer Frame . ITaskBarList . Scrolling Line Graph . Tray Icon Bar Graph . Explorer Listview . Wiimote . WinSnap . Flicker Free Labels . iTunesPrograms: Ftp Explorer . Snipster . Network Meter . Resistance Calculator Link to comment Share on other sites More sharing options...
kylomas Posted January 8, 2012 Share Posted January 8, 2012 (edited) 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 January 8, 2012 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 More sharing options...
Beege Posted January 8, 2012 Share Posted January 8, 2012 You can also look at function _TicksToTime(). It converts ms to Hours, minutes ,sec. Assembly Code: fasmg . fasm . BmpSearch . Au3 Syntax Highlighter . Bounce Multithreading Example . IDispatchASMUDFs: Explorer Frame . ITaskBarList . Scrolling Line Graph . Tray Icon Bar Graph . Explorer Listview . Wiimote . WinSnap . Flicker Free Labels . iTunesPrograms: Ftp Explorer . Snipster . Network Meter . Resistance Calculator Link to comment Share on other sites More sharing options...
myk3 Posted January 8, 2012 Author Share Posted January 8, 2012 I just found this.. and it works well.. @Kylomas I will try your since it seems cleaner.. Link to comment Share on other sites More sharing options...
myk3 Posted January 8, 2012 Author Share Posted January 8, 2012 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 This appears to just give the time since the last check.. am i wrong? Link to comment Share on other sites More sharing options...
myk3 Posted January 8, 2012 Author Share Posted January 8, 2012 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 More sharing options...
Beege Posted January 8, 2012 Share Posted January 8, 2012 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(). Assembly Code: fasmg . fasm . BmpSearch . Au3 Syntax Highlighter . Bounce Multithreading Example . IDispatchASMUDFs: Explorer Frame . ITaskBarList . Scrolling Line Graph . Tray Icon Bar Graph . Explorer Listview . Wiimote . WinSnap . Flicker Free Labels . iTunesPrograms: Ftp Explorer . Snipster . Network Meter . Resistance Calculator Link to comment Share on other sites More sharing options...
kylomas Posted January 8, 2012 Share Posted January 8, 2012 myk3, Yes, in seconds rounded to 2 decimal places...as Beege is alluding to, there a many ways to express time... 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 More sharing options...
Beege Posted January 8, 2012 Share Posted January 8, 2012 Many ways to skin a cat! Assembly Code: fasmg . fasm . BmpSearch . Au3 Syntax Highlighter . Bounce Multithreading Example . IDispatchASMUDFs: Explorer Frame . ITaskBarList . Scrolling Line Graph . Tray Icon Bar Graph . Explorer Listview . Wiimote . WinSnap . Flicker Free Labels . iTunesPrograms: Ftp Explorer . Snipster . Network Meter . Resistance Calculator 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