NewPlaza Posted January 1, 2013 Share Posted January 1, 2013 Hello, I've seen dozens of examples on how to copy folders with a progress bar. But find that I don't want to incorporate the code in my very simple/tiny scripts. Anyhow, I have come up with this bit of code. $sSourceFolder = "D:\!Drivers" $iSourceSize = DirGetSize($sSourceFolder) $sDestFolder = @DesktopDir & "\" & "TestDownloadFolder" Run(@AutoItExe & ' /AutoIt3ExecuteLine "DirCopy(''' & $sSourceFolder & ''', ''' & $sDestFolder & ''')"') ProgressOn("Progress Meter", "Increments every second", "0 percent") Do $iDestSize = DirGetSize($sDestFolder) $iPercent = Int($iDestSize / ($iSourceSize / 100)) ProgressSet($iPercent, $iPercent & " percent") Until $iPercent = 100 ProgressSet(100 , "Done", "Complete") Sleep(500) ProgressOff() I would like to know what the risks/danger of using such code. I can only come up with is there is no error checking if the folder copied or not. But I would image there or more risks I can't possible come up with. I welcome any advice/help. Thanks. Link to comment Share on other sites More sharing options...
GordonFreeman Posted January 1, 2013 Share Posted January 1, 2013 (edited) I like this code but need a sleep to not to stress the processor and not blink percentage $sSourceFolder = "D:\!Drivers" $iSourceSize = DirGetSize($sSourceFolder) $sDestFolder = @DesktopDir & "\" & "TestDownloadFolder" Run(@AutoItExe & ' /AutoIt3ExecuteLine "DirCopy(''' & $sSourceFolder & ''', ''' & $sDestFolder & ''')"') ProgressOn("Progress Meter", "Increments every second", "0 percent") Do $iDestSize = DirGetSize($sDestFolder) $iPercent = Int($iDestSize / ($iSourceSize / 100)) ProgressSet($iPercent, $iPercent & " percent") Sleep(200) Until $iPercent = 100 ProgressSet(100 , "Done", "Complete") Sleep(500) ProgressOff() Not to understand the part of the risks. Im a brazilian (PT-BR) xD Edited January 1, 2013 by GordonFreeman Frabjous Installation Link to comment Share on other sites More sharing options...
MilesAhead Posted January 1, 2013 Share Posted January 1, 2013 (edited) Or you can use _WinAPI_ShellFileOperation() from the WinAPIEx UDF. You may even get the Taskbar Progress in W7. The Shell does it all for you. Albeit it may be a bit slow doiing it. Edited January 1, 2013 by MilesAhead My Freeware Page Link to comment Share on other sites More sharing options...
NewPlaza Posted January 1, 2013 Author Share Posted January 1, 2013 @GordonFreeman Thanks for that. I does make it much smoother. @MilesAhead Yeah, I though & tried the WinAPI but I don't want anyway a user can cancel the copy. Thanks Link to comment Share on other sites More sharing options...
KaFu Posted January 1, 2013 Share Posted January 1, 2013 In SMF I switched to Yashied's excellent " which utilizes a copy.dll file to perform the operations. The script stays responsive, the copy process can be interrupted and you can measure the progress too. OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
guinness Posted January 1, 2013 Share Posted January 1, 2013 In SMF I switched to Yashied's excellent " which utilizes a copy.dll file to perform the operations. The script stays responsive, the copy process can be interrupted and you can measure the progress too.I second that suggestion too. 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...
kylomas Posted January 1, 2013 Share Posted January 1, 2013 Not to mention that you can interrogate the return from the copy process in Yashied's code whereas in the technique that you use has no visibility to the spawned process, as you metioned in the OP. However, if you elect to stay with your code the following may help: - changed the code to a function to make it easier to add to code/maintain - added delete for target dir as code will not work if target is not empty - changed % calculation - I believe the general formula is int((part/whole)*100) - changed to loop on the pid of the spawned process ; ; copy folder and subfolders with progress ; _CopyFolder(@scriptdir, @scriptdir & '\Temp out folder') func _CopyFolder($sSourceFolder,$sDestFolder) dirremove($sDestFolder,1) local $iSourceSize = DirGetSize($sSourceFolder), $iDestSize local $pid = Run(@AutoItExe & ' /AutoIt3ExecuteLine "DirCopy(''' & $sSourceFolder & ''', ''' & $sDestFolder & ''')"') ProgressOn("Copy Progress", "Please Wait...") Do $iDestSize = dirgetsize($sDestFolder) local $ipct = int(($iDestSize/$iSourceSize)*100) ProgressSet($ipct,$ipct & ' percent complete') sleep(20) Until not ProcessExists($pid) ProgressOff() endfunc Incidentally, your code shows that you are thinking and grasping the language, Good Job! 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...
guinness Posted January 1, 2013 Share Posted January 1, 2013 For efficency you should declare $ipct outside the loop. 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...
kylomas Posted January 1, 2013 Share Posted January 1, 2013 noted - Thank You Guinness 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...
TalivanIBM Posted May 25, 2013 Share Posted May 25, 2013 Thanks a lot man, i was looking for this, and now i have found it!!! Link to comment Share on other sites More sharing options...
Developers Jos Posted February 12, 2015 Developers Share Posted February 12, 2015 Do you mean that the line isn't executed so no files are copied? What version are you running? Have you added this at the top in case you run the latest version of AutoIt3?: #pragma compile(AutoItExecuteAllowed, true) Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Aler Posted October 16, 2017 Share Posted October 16, 2017 Hi I found the code from kylomas for DirCopy with progress (above) works great for me. Many thanks ! ! ! However, I have one small problem . . . I'm using the code to copy Audacity recording files from C:\...\My Documents\Audacity\ to a USB (E:\ drive). When I use the command: DirCopy($FilePath, $USBdrive, 1) normally (without progress), I can set $USBdrive to "E:\" and it all works fine. HOWEVER, when I call the _CopyFolder fuction above from within my script, I have found the destination drive MUST have a drive letter AND a folder name specified. Otherwise the script continues without copying anything! ie $sDestFolder MUST be set to something like: "E:\Audacity" - not just "E:\". Any ideas ? ? ? I can work around it but it would be nice to just use "E:\". Link to comment Share on other sites More sharing options...
benched42 Posted October 17, 2017 Share Posted October 17, 2017 I agree that it would be nice to use just "E:\" but you can't rely on the USB flash drive always being E: To get around this, use the "DriveGetDrive" function and check to see if it is of type "REMOVEABLE"; flash drives (as well as SD cards) show up as REMOVEABLE. Who lied and told you life would EVER be fair? 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