Jump to content

Copy with progress dialog...


Recommended Posts

  • 2 months later...
  • Replies 69
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

This code copies a folder content in an other folder that have to exist already. It shows a progress dialog with percent completed (calculed over size) and a fraction of action done (calculated with

Posted Images

just coooooooooooooooooooooool

[quote]Baby you're all that I want, When you're lyin' here in my armsI'm findin' it hard to believe, We're in heavenAnd love is all that I need , And I found it there in your heartIt isn't too hard to see, We're in heaven .Bryan Adams[/quote].............................................................................[u]AUTOIT[/u]

Link to post
Share on other sites

Is it possible to have this script overwrite files automatically? I know the built in FileCopy can, but then you loose the progress bar.

If your referring to the Com copy function, not sure. The link I show has the settings available and if you can achieve it, then yes. Only one way to find out is with a test script or something. I do not use it often enough to know.

:)

Link to post
Share on other sites

If your referring to the Com copy function, not sure. The link I show has the settings available and if you can achieve it, then yes. Only one way to find out is with a test script or something. I do not use it often enough to know.

:)

I saw that after I posted, and by the way the script is made it's supposed to answer 'YES TO ALL' and overwrite the files. When I first tested, I was on a Vista machine and figured it was changed (like everything else :D ) but I also tested in XP and it did not answer the overwrite prompt. :D

Link to post
Share on other sites
  • 1 month later...

same here

Line 0 (File "C:\Documents and Settings\Murray\My Documents\scripts\AutoIT3\Backup\BackupPowerTill.exe"):

Local $sIstr, $bSF, $sCriteria, $sBuffer, $iH, $iH2, $sCS, $sCF, $sCF2, $sCP, $sFP, $sOutPut = '', $aNull[1]

Local ^ ERROR

Error: Can not redeclare a parameter inside a user function.

Can anyone advise how to fix this script?

Best regards,

Murray

Link to post
Share on other sites

Can anyone advise how to fix this script?

Just remove $sIstr, from that line.

Edit: and $bSF, to

Edited by MsCreatoR

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to post
Share on other sites

Hi all,

Check this my version to copy dir with progress...

When copying, displayed number of copied files, "from" to "where" currently is copying, and also the "Approximately Remained Time" for copying:

Here the script: CopyWithCustomProgress.au3

I hope this will be usefull aswell.

Edit: The function _GetTimeRemained() need more testing, i can't get it to calculate all possible variations, if someone have time/wish, please look at it. Basicly there is need to check the process arch., memory load, and "realy" check how many time (how long) take certain "system state" to copy particular number of megabytes.

Edited by MsCreatoR

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to post
Share on other sites
  • 3 months later...

I figured it out. I added the following line:

If ( FileGetTime( $aFileList[$c],0,1) > FileGetTime( $sDestDir & $FileName,0,1 ) ) Then

EndIF

around this block of code where the copy takes place:

If Not FileCopy($aFileList[$c], $sDestDir & $FileName, 1) Then

If Not FileCopy($aFileList[$c], $sDestDir & $FileName, 1) Then ;Tries a second time

If RunWait(@ComSpec & ' /c copy /y "' & $aFileList[$c] & '" "' & $sDestDir & $FileName & '">' & @TempDir & '\o.tmp', '', @SW_HIDE)=1 Then;and a third time, but this time it takes the error message

$sError = FileReadLine(@TempDir & '\o.tmp',1)

$iOutPut = $iOutPut + 1

$sLost = $sLost & $aFileList[$c] & ' ' & $sError & @CRLF

EndIf

FileDelete(@TempDir & '\o.tmp')

EndIf

EndIf

I know the correct way to do this would be to pass in a parameter, create a list of the destination folder, then compare these if the parameter was set to newer only. I don't have time for that at the moment though.

Link to post
Share on other sites
  • 4 weeks later...
  • 7 months later...

Hi,

My first post and autoit script, so please be gentle with the newb :)

Need to create a progress bar for file copying, files are copied from multiple sources and accuracy is not so important.

I have tried the functions found in this forum, thanks to the authors, however a few questions:

Using the script in first post copying takes almost 1.5 times compared to using:

...
$winShell = ObjCreate("shell.application")
$winShell.namespace($todirectory).CopyHere($fromFile)
...

Directory copied had ~12 000 files, 1.1GB. First script took 328 seconds to complete, commenting out FileSetAttrib reduced just a few seconds. A regular DirCopy() took 213sec., winshell way- 196sec.

The one in post #49 needed 713sec with a long delay while getting directory information.

Measured with

Logging("DirCopy started")
$begin = TimerInit()
DirCopy("L:\_ftp", "l:\_ftp_temp")
$dif = TimerDiff($begin) / 1000
Logging("_DirCopy Completed" & " Took " & $dif)

What can be improved in the ezzetabi's for such sources, and what has to be added to accept multiple source directories.

I guess if cannot be improved much for speed, then I'd have to control the progress bar only per the number of files, would that avoid delay?

Or any other ideas?

Thanks in advance.

Edited by ilko
Link to post
Share on other sites

ok, then check out my try.

i took both of the script posted here, and worked on them, as i saw fit.

uses the same syntax, but with a custom made dialog, with avi, just like in windows.

i am certain someone can make a better one, this is my first script i post, but do check it out :)

#CS
;~ This script is demonstrate copy process with custom designed progress displayed, the progress display details about the copy process.
;~ 
;~ Syntax: _CopyWithProgress("C:\Source", "C:\Dest", 1)
;~ First parm is the source dir that files will be copied from.
;~ Second param is the destination path that files will be copied to.
;~ If the last parameter set as 1, then all existing files will be replaced with copied ones.
;~ 
;~ Author: G.Sandler a.k.a CreatoR
;~ Functions _DirListToArray() and _FileListToArrayEx() is originaly writen by amel27.
;~ Further modded by damian666
#CE

#include <AVIConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <File.au3>

;_CopyWithProgress("C:\Source", "C:\Dest", 1)

Func _CopyWithProgress($SourcePath, $DestPath, $Replace=0)
    If Not FileExists($SourcePath) Then Return SetError(1, 0, -1)
    If Not StringInStr(FileGetAttrib($DestPath), "D") And Not DirCreate($DestPath) Then Return SetError(2, 0, "")
    If $Replace <> 0 And $Replace <> 1 Then SetError(3, 0, "")
    
    Local $PathName = StringRegExpReplace($SourcePath, "^.*\\", "")
    Local $Progress=0, $Counter, $ReadySize, $MidlePath, $Ready, $TimeRemained
    Local $CurrentFilePath, $CurrentFileName, $CurrentFilePathName, $CurrentParentDirName
    
;ProgressOn("Copy Files...", "Copy: " & $PathName, "Getting dir structure" & @LF & "Please wait...", -1, -1, 2 + 16)
    
    Local $TotalDirSize = DirGetSize($SourcePath)
    Local $FilesArr = _FileListToArrayEx($SourcePath)
    Local $FilesCount = UBound($FilesArr)-1
    Local $ProgressStep = 100 / $FilesCount
    
;testdialog
    Opt("GUIOnEventMode", 1)
    #Region ### START Koda GUI section ### Form=C:\Documents and Settings\Administrator\Bureaublad\Form1.kxf
    $Form1 = GUICreate("Copying...", 401, 238, 193, 125, BitOR($WS_SYSMENU,$WS_CAPTION,$WS_POPUP,$WS_POPUPWINDOW,$WS_BORDER,$WS_CLIPSIBLINGS))
    $Avi1 = GUICtrlCreateAvi(@ScriptDir & "\160.avi", -1, 0, 0, 400, 56, BitOR($ACS_TRANSPARENT,$ACS_AUTOPLAY))
    $Progress1 = GUICtrlCreateProgress(8, 64, 385, 17)
    $Label1 = GUICtrlCreateLabel("From:", 8, 112, 36, 17)
    $Label2 = GUICtrlCreateLabel("", 56, 112, 338, 25)
    $Label3 = GUICtrlCreateLabel("Filecopy in progress...", 8, 88, 385, 17)
    $Label4 = GUICtrlCreateLabel("To:", 8, 152, 36, 17)
    $Label5 = GUICtrlCreateLabel("", 56, 151, 338, 25)
    $Button1 = GUICtrlCreateButton("Cancel", 337, 216, 59, 17, 0)
    GUICtrlSetOnEvent(-1, "Button1Click")
    $Label6 = GUICtrlCreateLabel("Approximately Remained Time:", 8, 184, 156, 17)
    $Label7 = GUICtrlCreateLabel("", 176, 184, 217, 17)
    $Label8 = GUICtrlCreateLabel("Already done:", 8, 208, 69, 17)
    $Label9 = GUICtrlCreateLabel("", 88, 208, 243, 17)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    
;end testdialog
    
    If IsArray($FilesArr) Then
        For $i = 1 To UBound($FilesArr)-1
            $CurrentFilePath = $FilesArr[$i]
            $CurrentFileName = StringRegExpReplace($CurrentFilePath, "^.*\\", "")
            $CurrentFilePathName = StringReplace($CurrentFilePath, $SourcePath & "\", "")
            
            $CurrentParentDirName = _GetParentDirName($CurrentFilePath)
            
            $Progress += $ProgressStep
            $Counter += 1
            
            $ReadySize = FileGetSize($CurrentFilePath)
            
            $MidlePath = _GetMidlePath($CurrentFilePath)
            $Ready = $Counter & "/" & $FilesCount
            $TimeRemained = _GetTimeRemained($TotalDirSize, $ReadySize, $FilesCount, $Counter)
            
            GUICtrlSetData($Label2, $CurrentFilePath)
            GUICtrlSetData($Label5, $DestPath & "\" & $CurrentFilePathName)
            GUICtrlSetData($Progress1, $Progress)
            GUICtrlSetData($Label7, $TimeRemained)
            GUICtrlSetData($Label9, $Ready)
            
        ;ProgressSet($Progress, "Copy... from " & $CurrentParentDirName & " to " & $CurrentParentDirName & @LF & _
            ;$MidlePath & @LF & "Approximately Remained Time: " & $TimeRemained, "Ready: " & $Ready)
            FileCopy($CurrentFilePath, $DestPath & "\" & $CurrentFilePathName, 8+$Replace)
        Next
    EndIf
;ProgressOff()
EndFunc

Func _FileListToArrayEx($sPath, $sMask='*')
    Local $i, $j, $blist, $rlist[1]=[0], $dlist = _DirListToArray($sPath)
    _ArrayAdd ($dlist, $sPath)
    For $i=1 To $dlist [0] +1
        $blist = _FileListToArray ($dlist [$i], $sMask, 1)
        If Not @error Then
            For $j=1 To $blist [0]
                _ArrayAdd ($rlist, $dlist[$i] & "\" & $blist [$j])
            Next
        EndIf
    Next
    $rlist [0] = UBound ($rlist) - 1
    Return $rlist
EndFunc

Func _DirListToArray($sPath)
    Local $rlist[2]=[1, $sPath], $blist, $alist=_FileListToArray ($sPath, '*', 2)
    If IsArray ($alist) Then
        For $i=1 To $alist [0]
            _ArrayAdd ($rlist, $sPath & "\" & $alist [$i])
            $blist = _DirListToArray ($sPath & "\" & $alist [$i])
            If $blist[0]>0 Then
                For $j=1 To $blist [0]
                    _ArrayAdd ($rlist, $blist [$j])
                Next
            EndIf
        Next
    EndIf
    $rlist[0] = UBound($rlist) - 1
    Return $rlist
EndFunc

Func _GetMidlePath($sPath)
    If StringLen($sPath) <= 50 Then Return $sPath
    Local $StartPath = StringLeft($sPath, 25)
    Local $EndPath = StringTrimLeft($sPath, StringInStr($sPath, "\", 0, -2)-1)
    Return $StartPath & "..." & $EndPath
EndFunc

Func _GetParentDirName($FullName)
    Local $LastSlashPos = StringInStr($FullName, "\", 0, -1)
    Local $SecondLastSlashPos = StringInStr($FullName, "\", 0, -2)
    Return StringMid($FullName, $SecondLastSlashPos+1, $LastSlashPos-$SecondLastSlashPos-1)
EndFunc

Func _GetTimeRemained($TotalSize, $CurrentSize, $FilesCount, $CurrentFilesCount)
    Local $NumLevl = 0.5
    
    If $TotalSize <= $CurrentSize Then Return _SecsToTime(0)
    
    Switch $FilesCount - $CurrentFilesCount
        Case 0 To 100
            $NumLevl = 0.1
        Case 100 To 1000
            $NumLevl = 0.5
        Case 1000 to 2000
            $NumLevl = 1
        Case Else
            $NumLevl = 2
    EndSwitch
    
    $Secs = ($TotalSize * $NumLevl) / (3600 * $CurrentFilesCount) - ($CurrentSize * $NumLevl) / (3600 * $CurrentFilesCount)
    Return _SecsToTime($Secs)
EndFunc

Func _SecsToTime($iTicks, $Delim=":")
    If Number($iTicks) >= 0 Then
        $iHours = Int($iTicks / 3600)
        $iTicks = Mod($iTicks, 3600)
        $iMins = Int($iTicks / 60)
        $iSecs = Round(Mod($iTicks, 60))
        If StringLen($iHours) = 1 Then $iHours = "0" & $iHours
        If StringLen($iMins) = 1 Then $iMins = "0" & $iMins
        If StringLen($iSecs) = 1 Then $iSecs = "0" & $iSecs
        Return $iHours & $Delim & $iMins & $Delim & $iSecs
    EndIf
    Return SetError(1, 0, 0)
EndFunc

Func Button1Click()
    Exit
EndFunc

let me know what you think, oh and dont forget the avi in the same dir for now...

Damian666

and proud of it!!!
Link to post
Share on other sites

ok, then check out my try.

i took both of the script posted here, and worked on them, as i saw fit.

uses the same syntax, but with a custom made dialog, with avi, just like in windows.

i am certain someone can make a better one, this is my first script i post, but do check it out :)

let me know what you think, oh and dont forget the avi in the same dir for now...

Damian666

Why reinvent the wheel?

There is Windows API SHFileOperation ($FO_COPY) which will do all the work for you :)

Look here: http://www.autoitscript.com/forum/index.ph...st&p=527285

Link to post
Share on other sites

Damn, that is a good piece of code man. your a script god :)

thanx alot

damian666

p.s. what about moving instead of copying?

This code is not from me. I just updated old script to be compatible with AutoIt 3.2.10 version

corrected little bug with Chr(0) separator and slightly simplified it.

For moving just use $FO_MOVE instead of $FO_COPY. All $FO_xxx constants are already defined in script.

Edited by Zedna
Link to post
Share on other sites
  • 3 months later...

D:\Autoit\copy.au3 (88) : ==> Can not redeclare a parameter inside a user function.:

Local $sIstr, $bSF, $sCriteria, $sBuffer, $iH, $iH2, $sCS, $sCF, $sCF2, $sCP, $sFP, $sOutPut = '', $aNull[1]

Local ^ ERROR

>Exit code: 1 Time: 0.848

Website: www.cerescode.comForum: www.forum.cerescode.comIRC: irc.freenode.net , Channel: #Ceres--------------------Autoit Wrappers, Great additions to your script (Must See) (By: Valuater)Read It Befor Asking Question Click Here...--------------------Join Monoceres's Forums http://www.monoceres.se--------------------There are three kinds of people: Those who make things happen, those who watch things happen, and those who ask, ‘What happened?’” –Casey Stengel
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...