Sign in to follow this  
Followers 0
NewPlaza

DirCopy w/progress alternate

13 posts in this topic

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.

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by GordonFreeman

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 by MilesAhead

Share this post


Link to post
Share on other sites

@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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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: 04/09/2015

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

For efficency you should declare $ipct outside the loop.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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: 04/09/2015

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Thanks a lot man, i was looking for this, and now i have found it!!!

Share this post


Link to post
Share on other sites

Hi, everyone.

First thanks for the script. but i have a problem when i compile the script. if i run the script pressing f5 it´s all right but when i compile the script the line:

Run(@AutoItExe & ' /AutoIt3ExecuteLine "DirCopy(''' & $sSourceFolder & ''', ''' & $sDestFolder & ''')"')

don´t do the spected, the progress bar stay freezed and don´t continue, in any line with the run command i need to say it the WorkingDir, and in this example i dónt see it, maybe i was wrong but i don´t understand my mistake in this line, i only copy and paste and later i modify the source and destination, nothing more.

why when i press f5 all it´s fine but when i compile all it´s wrong?

thanks.

Christian

Share this post


Link to post
Share on other sites

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


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

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

Exactly, the script pause the execution in the window of progress and don´t continue, it´s not copying anything.

but you are the men.

this line was the solution of my problems:

#pragma compile(AutoItExecuteAllowed, true)

now it´s working perfect.

my autoit version is

SciTE

Version 3.4.1

 

I don´t know how this line work, i need to read about it.

Thanks a Lot Jos for your contribution to my work.

Christian

Share this post


Link to post
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
Sign in to follow this  
Followers 0