Jump to content

Adding progress bar to use with robocopy


adr
 Share

Recommended Posts

Hi , i'm new in programming and expecially in Autoit!

I'm trying to make an interface for my backup, which I do with .cmd files and robocopy.

I did it, now I have a window with some buttons, when I push a button it launches the .cmd file wich launches the copy with robocopy, and it works fine!

Now I'm pretending something better ... I would like to have 2 more things:

1: a progress bar which ends when the robocopy process ends

2: when the copy ends i would like to open the .log file produced by robocopy

I think it's possible but until now i do not know how to do it... I discovered autoit only yesterday.

Have you some hints?

Ah.. this is my script (only button ONE is the good one!!! ):

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****

#AutoIt3Wrapper_outfile=QB_Backup.exe

#AutoIt3Wrapper_UseX64=n

#AutoIt3Wrapper_Add_Constants=n

#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <ButtonConstants.au3>

#include <GUIConstantsEx.au3>

#include <StaticConstants.au3>

#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=

$Form1 = GUICreate("QB Backup", 331, 305)

GUISetBkColor(0x3A6EA5)

$Label1 = GUICtrlCreateLabel("Quale cartella vuoi copiare?", 32, 15, 237, 28)

GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")

$Button1 = GUICtrlCreateButton("provalog", 40, 60, 110, 35, $WS_GROUP)

$Button2 = GUICtrlCreateButton("DOC GUERRA",160, 60, 110, 35, $WS_GROUP)

$Button3 = GUICtrlCreateButton("DOCUMENTARI", 40, 105, 110, 35, $WS_GROUP)

$Button4 = GUICtrlCreateButton("FILM", 160, 105, 110, 35, $WS_GROUP)

$Button5 = GUICtrlCreateButton("FILM GUERRA", 40, 150, 110, 35, $WS_GROUP)

$Button6 = GUICtrlCreateButton("SERIE TV", 160, 150, 110, 35, $WS_GROUP)

$Button7 = GUICtrlCreateButton("TUTTODANTE", 40, 195, 110, 35, $WS_GROUP)

$Button8 = GUICtrlCreateButton("VIDEOMUSIC", 160, 195, 110, 35, $WS_GROUP)

$Button9 = GUICtrlCreateButton("YOUTUBE", 40, 240, 110, 35, $WS_GROUP)

$Button10 = GUICtrlCreateButton("Chiudi", 160, 240, 110, 35, $WS_GROUP)

GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")

GUICtrlSetBkColor(-1, 0xFF0000)

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1

$nMsg = GUIGetMsg()

Select

Case $nMsg = $Button1

Run('c:\autoitprove\robocopy\provalog.cmd')

Case $nMsg = $Button2

Run('docguerra.cmd')

Case $nMsg = $Button3

Run('documentari.cmd')

Case $nMsg = $Button4

Run('film.cmd')

Case $nMsg = $Button5

Run('filmguerra.cmd')

Case $nMsg = $Button6

Run('serietv.cmd')

Case $nMsg = $Button7

Run('tuttodante.cmd')

Case $nMsg = $Button8

Run('videomusic.cmd')

Case $nMsg = $Button9

Run('youtube.cmd')

Case $nMsg = $Button10

ExitLoop

Case $nMsg = $GUI_EVENT_CLOSE

ExitLoop

EndSelect

WEnd

Edited by adr
Link to comment
Share on other sites

I think it can be done like this:

Reason for post another script in this reply that:

I dont know which commands executed in your script => provalog.cmd

But i think you can modify your script like which i post in this reply.

P.S Welcome to autoitscript.com :(

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <File.au3>
If FileExists(@TempDir&"\coyingdata.dat") Then
    FileDelete(@TempDir&"\coyingdata.dat")
EndIf

DirCreate(@HomeDrive&"\Dir")
Dim $avarray
RunWait("cmd.exe /c dir /B *.* >>"&@TempDir&"\coyingdata.dat",@ScriptDir,@SW_HIDE)
_FileReadToArray(@TempDir&"\coyingdata.dat",$avarray)

#Region ### START Koda GUI section ### Form=Form1.kxf
$Form1 = GUICreate("Test", 459, 191, 192, 124)
$Button1 = GUICtrlCreateButton("Do it Now", 144, 136, 153, 25, $WS_GROUP)
$Progress1 = GUICtrlCreateProgress(48, 24, 361, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            For $i=0 To $avarray[0]


            RunWait("cmd.exe /c " & "copy /b " & $avarray[$i] & " " & @HomeDrive&"\dir",@ScriptDir,@SW_HIDE)
            GUICtrlSetData($Progress1,$i / $avarray[0] * 100)
        Next
        FileDelete(@TempDir&"\coyingdata.dat")
MsgBox(64,"Operation Done!","Operation Done!",3)

Exit
    EndSwitch
WEnd
[size="5"] [/size]
Link to comment
Share on other sites

I think it can be done like this:

Reason for post another script in this reply that:

I dont know which commands executed in your script => provalog.cmd

But i think you can modify your script like which i post in this reply.

P.S Welcome to autoitscript.com :(

Uhhh it's hard to understand, I'll study ! This is the provalog.cmd:

robocopy "d:\cartellaa" "d:\cartellab" /V /E /R:2 /W:5 /MIR /COPY:DT /LOG:c:\autoitprove\robocopy\log\provalog.log

exit

It's only a command of copy with robocopy.

Thank you for your answer, I have to study a bit this script ...

Edited by adr
Link to comment
Share on other sites

Hi adr.

You are going here:

This script and robocopy.exe will be in same directory.

+ No need use batch files.It can be done with runwait().

Also i add Progress bar for you.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=QB_Backup.exe
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Add_Constants=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <File.au3>
Dim $avarray

If FileExists(@TempDir&"\coyingdata.dat") Then
    FileDelete(@TempDir&"\coyingdata.dat")
EndIf

;http://www.microsoft.com/downloads/details.aspx?FamilyID=9D467A69-57FF-4AE7-96EE-B18C4790CFFD&displaylang=en

RunWait("cmd.exe /c dir /B d:\cartellaa\>"&@TempDir&"\coyingdata.dat",@ScriptDir,@SW_HIDE)
_FileReadToArray(@TempDir&"\coyingdata.dat",$avarray)

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("QB Backup", 332, 368, 192, 125)     ;$Form1_1 = GUICreate("QB Backup", 332, 368, 192, 125)
GUISetBkColor(0x3A6EA5)
$Label1 = GUICtrlCreateLabel("Quale cartella vuoi copiare?", 32, 15, 237, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Button1 = GUICtrlCreateButton("provalog", 40, 60, 110, 35, $WS_GROUP)
$Button2 = GUICtrlCreateButton("DOC GUERRA",160, 60, 110, 35, $WS_GROUP)
$Button3 = GUICtrlCreateButton("DOCUMENTARI", 40, 105, 110, 35, $WS_GROUP)
$Button4 = GUICtrlCreateButton("FILM", 160, 105, 110, 35, $WS_GROUP)
$Button5 = GUICtrlCreateButton("FILM GUERRA", 40, 150, 110, 35, $WS_GROUP)
$Button6 = GUICtrlCreateButton("SERIE TV", 160, 150, 110, 35, $WS_GROUP)
$Button7 = GUICtrlCreateButton("TUTTODANTE", 40, 195, 110, 35, $WS_GROUP)
$Button8 = GUICtrlCreateButton("VIDEOMUSIC", 160, 195, 110, 35, $WS_GROUP)
$Button9 = GUICtrlCreateButton("YOUTUBE", 40, 240, 110, 35, $WS_GROUP)
$Button10 = GUICtrlCreateButton("Chiudi", 160, 240, 110, 35, $WS_GROUP)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, 0xFF0000)


GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
$nMsg = GUIGetMsg()
Select
    Case $nMsg = $Button1
        $Progress1 = GUICtrlCreateProgress(24, 304, 273, 25)
        ;This is a easy way.
        For $i=0 To $avarray[0]


RunWait("cmd.exe /c " & "robocopy.exe " & "d:\cartellaa\"&$avarray[$i] & " " & "d:\cartellab\" & " " & "/V /E /R:2 /W:5 /MIR /COPY:DT /LOG:"&@HomeDrive&"\autoitprove\robocopy\log\provalog.log",@ScriptDir,@SW_HIDE)


GUICtrlSetData($Progress1,$i / $avarray[0] * 100)
    Next
    FileDelete(@TempDir&"\coyingdata.dat")
        $answer=MsgBox(65,"","Done! Watch Log?",10)
        if $answer="1" Then
            RunWait("cmd.exe /c " & @HomeDrive&"\autoitprove\robocopy\log\provalog.log",@ScriptDir,@SW_HIDE)
            EndIf


        ;Run("cmd.exe /c " & @HomeDrive&"\autoitprove\robocopy\provalog.cmd",@ScriptDir,@SW_HIDE)
;Run('c:\autoitprove\robocopy\provalog.cmd')


;old

Case $nMsg = $Button2
Run('docguerra.cmd')    ; it is In c:\autoitprove\robocopy\     ? or in ? i didn`t understand
Case $nMsg = $Button3
Run('documentari.cmd')
Case $nMsg = $Button4
Run('film.cmd')
Case $nMsg = $Button5
Run('filmguerra.cmd')
Case $nMsg = $Button6
Run('serietv.cmd')
Case $nMsg = $Button7
Run('tuttodante.cmd')
Case $nMsg = $Button8
Run('videomusic.cmd')
Case $nMsg = $Button9
Run('youtube.cmd')
Case $nMsg = $Button10
ExitLoop
Case $nMsg = $GUI_EVENT_CLOSE
ExitLoop

EndSelect


WEnd

edit:correction on script

+

Everythink correct but i cannot understand why it didnt want copy some dirs.

Edited by Sh3llC043r
[size="5"] [/size]
Link to comment
Share on other sites

Hi adr.

You are going here:

This script and robocopy.exe will be in same directory.

+ No need use batch files.It can be done with runwait().

Also i add Progress bar for you.

During the week I'll try the scipt and to understand what it does... :( , meanwhile thankyou very much!
Link to comment
Share on other sites

Ohhh great job, now I know how to implement "command lines" in the script without using external batch, greath thing!

I have only a problem, in this line I think:

RunWait("cmd.exe /c " & "robocopy.exe " & "d:\cartellaa\"&$avarray[$i] & " " & "d:\cartellab\" & " " & "/V /E /R:2 /W:5 /MIR /COPY:DT /LOG:"&@HomeDrive&"\autoitprove\robocopy\log\provalog.log",@ScriptDir,@SW_HIDE)

this command tries to copy d:\cartella\nameofthelastfile\ as a folder! and "nameofthelastfile" is a file and not a folder, so the log of robocopy gives me an error saying that that folder doesn't exists! (it doesn't copy the content of d:\cartellaa\, but tries to copy d:\cartellaa\nameofthelastfile). Thank you again for your courtesy!

Link to comment
Share on other sites

This does not use robocopy.

This script uses AutoIt's DirCopy() and FileCopy() to copy a directory with all its sub-directories and files to another location - with a progress bar window.

This works on my XP.

; Copy from AutoIt installed directory - possibly C:\Program Files\AutoIt3\SciTE\cSnippet
Local $CopyDirFrom = RegRead("HKLM\SOFTWARE\AutoIt v3\AutoIt", "InstallDir") & "\SciTE\cSnippet"
Local $CopyDirTo = @TempDir & "\cSnippet"
Local $avarray, $text, $Pid

$Pid = Run('"' & @ComSpec & '" /c dir "' & $CopyDirFrom & '\*.*" /B /O:N', '', @SW_HIDE, 2 + 4)
While 1
    $text &= StdoutRead($Pid, False, False)
    If @error Then ExitLoop
    Sleep(10)
WEnd

$text = StringStripWS($text, 7) ; Remove unwanted @CRLF's
$avarray = StringSplit($text, @CRLF, 0)

ProgressOn("Copy Files Progress", "No. of files left to copy = " & $avarray[0], "0 percent done")
For $i = 0 To $avarray[0]
    If FileGetAttrib($CopyDirFrom & "\" & $avarray[$i]) = "D" Then
        DirCopy($CopyDirFrom & "\" & $avarray[$i], $CopyDirTo & "\" & $avarray[$i], 1)
    Else
        FileCopy($CopyDirFrom & "\" & $avarray[$i], $CopyDirTo & "\" & $avarray[$i], 9)
    EndIf

    ProgressSet(Round(100 - ($i / $avarray[0] * 100), 1), _
            StringFormat("%4.1f percent done", Round($i / $avarray[0] * 100, 1)), _
            "No. of files left to copy = " & $avarray[0] - $i)
Next
ProgressOff ( )

Local $iBut = MsgBox(4, "Operation Done!", 'Press "Yes" to delete newly created directory in Temp Directory.')
If $iBut = 6 Then FileRecycle($CopyDirTo)

And here it is again using _FileListToArray() instead of the Run(@ComSpec.... routine.

I believe this one to be the faster.

#include <File.au3>

; Copy from AutoIt installed directory - possibly C:\Program Files\AutoIt3\SciTE\cSnippet
Local $CopyDirFrom = RegRead("HKLM\SOFTWARE\AutoIt v3\AutoIt", "InstallDir") & "\SciTE\cSnippet"
Local $CopyDirTo = @TempDir & "\cSnippet"
Local $avarray, $text, $Pid

$avarray = _FileListToArray($CopyDirFrom, "*.*")

ProgressOn("Copy Files Progress", "No. of files left to copy = " & $avarray[0], "0 percent done")
For $i = 0 To $avarray[0]
    If FileGetAttrib($CopyDirFrom & "\" & $avarray[$i]) = "D" Then
    DirCopy($CopyDirFrom & "\" & $avarray[$i], $CopyDirTo & "\" & $avarray[$i], 1)
    Else
    FileCopy($CopyDirFrom & "\" & $avarray[$i], $CopyDirTo & "\" & $avarray[$i], 9)
    EndIf

    ProgressSet(Round(100 - ($i / $avarray[0] * 100), 1), _
    StringFormat("%4.1f percent done", Round($i / $avarray[0] * 100, 1)), _
    "No. of files left to copy = " & $avarray[0] - $i)
Next
ProgressOff ( )

Local $iBut = MsgBox(4, "Operation Done!", 'Press "Yes" to delete newly created directory in Temp Directory.')
If $iBut = 6 Then FileRecycle($CopyDirTo)
Edited by Malkey
Link to comment
Share on other sites

  • 1 year later...

Here my code for a 2 progressbar robocopy It does a basic roboopy I am working on adding in additional options such as /mov and the like the problem is the more options givn the more chance for users to choose invalid switches, and robocopy is not very forgiving

#include <GUIConstants.au3>
#include <file.au3>
#include<Constants.au3>
Global $FProgress
$GUI = GUICreate("Progress", 500, 200)
$SourceLabel = GUICtrlCreateInput("Select the Source Folder:", 10, 15, 380, 17)
$SourceBtn = GUICtrlCreateButton("...",400, 10, 25, 25)
$DestLabel = GUICtrlCreateInput("Select the Destination Folder:", 10, 40, 380, 17)
$DestBtn = GUICtrlCreateButton("...",400, 35, 25, 25)
GUICtrlCreateLabel("Current File: ", 10, 70)
$fileLbl = GUICtrlCreateLabel("N/A", 75, 70, 400)
GUICtrlCreateLabel("Current File Size: ", 10, 90)
$sizeLbl = GUICtrlCreateLabel("N/A", 95, 90, 105)
$progress = GUICtrlCreateProgress(10, 115, 480)
$Fullprogress = GUICtrlCreateProgress(10, 145, 480)
$GoBtn = GUICtrlCreateButton("GO", 205, 170, 40, 25)
$ExitBtn = GUICtrlCreateButton("EXIT", 275, 170, 40, 25)
$VerboseLogs=GUICtrlCreateCheckbox("Verbose Logging ON",25, 170, 150, 25)
_DisableFormControls()
GUISetState()
_EnableFormControl($SourceLabel)
_EnableFormControl($SourceBtn)
_EnableFormControl($ExitBtn)
_EnableFormControl($VerboseLogs)
$FProgress=0
$AppLogFile=@AppDataCommonDir &"AppLOG.LOG"
$NoCopyLog=@AppDataCommonDir &"NoCopyLOG.LOG"
$CopyLog=@AppDataCommonDir &"CopyLOG.LOG"
$ProcessBarLog=@AppDataCommonDir &"ProcessBarLOG.LOG"
Local $Destination, $Source, $tempOutput
_Writelog(1, "Application Launched")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
  Case $SourceBtn
   _Writelog(1, "Source Button Clicked")
   $Source=_GetSourceDir()
   _Writelog(1, "Source set to" & $Source)
   GUICtrlSetData($SourceLabel,$Source)
   _Writelog(1, "GUI Source Input box updated to" & $Source)
   _EnableFormControl($DestLabel)
   _EnableFormControl( $DestBtn)
  Case $DestBtn
   _Writelog(1, "Destination Button Clicked")
   $Destination=_GetDestinationDir()
   _Writelog(1, "Source set to" & $Destination)
   GUICtrlSetData($DestLabel,$Destination)
   _Writelog(1, "GUI Source Input box updated to" & $Destination)
   _EnableFormControl($GoBtn)
  Case $GoBtn
   _Writelog(1, "Go Button Clicked")
   _Writelog(1, "Disable Form Controls")
   _DisableFormControls()
   $Source=GUICtrlRead($SourceLabel)
   $Destination=GUICtrlRead($DestLabel)
   _Writelog(1, "Launching Dummy Copier to determine number of files and size to be copied from " &$Source& " to " & $Destination)
   $errors=_ErrorChecking($Source, $Destination)
   _Writelog(1, "Error Level returned =" & $errors)
   If $errors = 0 Then
    $NumFiles=_DummyCopy($Source, $Destination)
    _Writelog(1, "The Number of files to be transfered at CASE = " &$NumFiles)
    _Writelog(1, "Launching Copier to copy from " &$Source& " to " & $Destination)
    _Copier($Source, $Destination, $NumFiles)
    _Writelog(1, "Copy function Completed")
    _EnableFormControl($SourceLabel)
    _EnableFormControl($SourceBtn)
    _EnableFormControl($ExitBtn)
    _EnableFormControl($VerboseLogs)
  
   Else
    MsgBox(1, "Copy", "Copy has NOT been run due to issues")
   EndIf
  Case $ExitBtn
   _Writelog(1, "Exit Button Clicked")
   _ExitProgram()

EndSwitch
WEnd
Func _ExitProgram()
_Writelog(1, "User has closed the application")
Exit
EndFunc
Func _GetSourceDir()
_Writelog(1, "Selecting Source Directory")
$SourceDir=FileSelectFolder("Get Source", "", 2, "EditPlus 2")
If Stringlen($SourceDir) = 3 Then
  If StringInStr($SourceDir, "") =3 Then
  _Writelog(1, "Detected a root drive" &$SourceDir & " Trimming the  of the end")
  $SourceDir=StringTrimRight($SourceDir,1)
  EndIf
EndIf
_Writelog(1, "Selected Source Directory - " &$SourceDir)
Return $SourceDir
_Writelog(1, "Returning Source Directory - " &$SourceDir)
EndFunc
Func _GetDestinationDir()
_Writelog(1, "Selecting Destination Directory")
$DestinationDir=FileSelectFolder("Select Destination", "", 1, "EditPlus 2")
If Stringlen($DestinationDir) = 3 Then
  If StringInStr($DestinationDir, "") =3 Then
  _Writelog(1, "Detected a root drive" &$DestinationDir & " Trimming the  of the end")
  $DestinationDir=StringTrimRight($DestinationDir,1)
  EndIf
EndIf
_Writelog(1, "Selected Destination Directory - " &$DestinationDir)
Return $DestinationDir
_Writelog(1, "Returning Destination Directory - " &$DestinationDir)
EndFunc
Func _ErrorChecking($Source, $Destination)
Local $Result
$result=0
_Writelog(1, "Checking for known Issues")
If $Source = "" Then
  _Writelog(1, "Source Directory has not been Selected")
  MsgBox(1, "WARNING", "Source Directory has not been Selected")
  $Result=1
EndIf
If $Destination = "" Then
  _Writelog(1, "Destination Directory has not been Selected")
  MsgBox(1, "WARNING", "Destination Directory has not been Selected")
  $Result=1
EndIf
$SourceColon=StringInStr($Source, ":")
$SourceSlash=StringInStr($Source, "")
If $SourceColon=0 or $SourceSlash=0 Then
  _Writelog(1, "Source Directory has not been Selected based on the second character being either a : or 1st character being a ")
  MsgBox(1, "WARNING", "Source Directory in not valid")
  $Result=1
EndIf
$DestColon=StringInStr($Destination, ":")
$DestSlash=StringInStr($Destination, "")
If $DestColon=0 or $DestSlash=0 Then
  _Writelog(1, "Destination Directory has not been Selected based on the second character being either a : or 1st character being a ")
  MsgBox(1, "WARNING", "Destination Directory in not valid" & $DestColon)
  $Result=1
EndIf
If StringInStr($Destination, $Source &"", 2, 1, 1) <> 0 Then
  _Writelog(1, "Destination Directory is inside the Source Directory")
  MsgBox(1, "WARNING", "Destination Directory  is inside the Source Directory")
  $Result=1
EndIf
  If Stringlen($Source) = 3 Then
  If StringInStr($Source, "") =3 Then
  _Writelog(1, "Detected a root drive" &$Source & " Trim the  of the end")
  MsgBox(1, "WARNING", "Source Directory  is a root directory remove the last ")
  $Result=1
  EndIf
EndIf
If Stringlen($Destination) = 3 Then
  If StringInStr($Destination, "") =3 Then
  _Writelog(1, "Detected a root drive" &$Destination & " Trim the  of the end")
  MsgBox(1, "WARNING", "Destination Directory  is a root directory remove the last ")
  $Result=1
  EndIf
EndIf
Return $Result
EndFunc
Func _Copier($sourcedir, $destdir, $NumFiles)
_Writelog(1, "Copy Function Launched")
_Writelog(1, "Ressetting Progress Bars to Zero")
GUICtrlSetData($progress, 0)
GUICtrlSetData($Fullprogress, 0)
$RoboJob=@ComSpec & " /c " & 'robocopy.exe "' & $sourcedir & '" "' & $destdir & '" /TEE /E /V /Log:'&$CopyLog
_Writelog(1, "Copy started " &$RoboJob )
_Writelog(1, "See Robocopy Log for more detailed information or the RoboCopy" )
$copyjob = Run ($RoboJob, @ScriptDir, @SW_Hide, 2 )
_UpdateFileProgress($copyJob , $sourcedir , $destdir, $NumFiles)
_Writelog(1, "Copy Finished " &$RoboJob )

EndFunc
Func _DummyCopy($sourcedir, $destdir)
Local $ReadArray
_Writelog(1, "Dummy Copy Function Launched")
$RoboDummyJob=@ComSpec & ' /c ' & 'robocopy.exe "' & $sourcedir & '" "' & $destdir & '" /NOCOPY /S /TEE /L /Log:'&$NoCopyLog
$Nocopyjob = Run ($RoboDummyJob, @ScriptDir, @SW_Hide, 2 )
_Writelog(1, "Dummy Copy started " &$RoboDummyJob )
While ProcessExists($Nocopyjob)
  _Writelog(1, "Sleeping while NoCopy Job is Running Process =" &$Nocopyjob )
  Sleep(10)
WEnd
_Writelog(1, "Job is Completed Process =" &$Nocopyjob )
If Not _FileReadToArray($NoCopyLog, $ReadArray) Then
   _Writelog(1, "ERROR reading log to Array  ERROR:" & @error)
   Exit
EndIf
For $x = 1 to $ReadArray[0]
_Writelog(1, "Reading " &$NocopyLog& " as Array ")
_Writelog(1, "Line "&$x&" = " &$ReadArray[$x])
  $Filesname=StringInStr($ReadArray[$x], "Files :")
  If $FilesName <> 0 Then
  _Writelog(1, "Line "&$x&" = " &$ReadArray[$x] & " Contains the word Files at position " &$Filesname)
  $allfiles=StringInStr($ReadArray[$x], "*.*")
  If $allfiles = 0 Then
   $TempFilesNum=StringTrimLeft($ReadArray[$x],Int($FilesName + 6))
   _Writelog(1,"String has been created" & $TempFilesNum)
   $TempFilesNumArray=StringRegExp($TempFilesNum, "S+",3)
    for $i = 0 to UBound($TempFilesNumArray) - 1
     _Writelog(1, "Split files line into array. Array " & $i & " =" & $TempFilesNumArray[$i])
    Next
   $FilesName=$TempFilesNumArray[0]
    _Writelog(1, $filesName & " The Number of files to be transfered at dummy copy")
    Return ($filesName)
  EndIF
EndIf
Next
EndFunc
Func _UpdateFileProgress($copyJob , $sourcedir , $destdir, $NumFiles)
_Writelog(4, "Update Progress Function Started" )
_Writelog(1, "The Number of files to be transfered at UpdateFileProress func =  " &$NumFiles)
$switch = 0; We don't want to run StringRegExp on lines that don't matter to us
$output = ""
While ProcessExists($copyjob)
_Writelog(4, "Running while Process Exists" & $copyJob )
$tempOutput =  StdoutRead($copyjob , False , False)
_Writelog(4, "StdoutRead($copyjob , False , False) = " & $tempOutput )
$tempOutput=StringRegExpReplace($tempOutput, "^( *)(.*)$", "1") ; Captures leading spaces in string
If not $tempOutput = "" or " " Then
_Writelog(4, "$tempOutput is not Blank it is = " & $tempOutput )
;ElseIf  StringInStr($tempOutput, "Started :") <> 0 Then
         $output = $tempOutput
   _Writelog(4, "StdoutRead to be processed = " & $output )
     $output = StringSplit($output, @CRLf)
            For $i = 1 To $output[0] - 1
    _Writelog(4, "StdoutRead Output Split by @CRLF= " & $output[$i] )
    If $output[$i] = " " Then
    _Writelog(4, "Determined as blank = " & $output[$i] )
    Else
     _Writelog(4, "Determined as not blank = " & $output[$i] )
     If  Not $switch Then
     _Writelog(4, "Output does not =  0")
     _Writelog(4, "Splitting Output["&$i& "] by any digit group and space groups" )
      If StringRegExp($output[$i], 'd+s+' & StringReplace($sourcedir, "", "")) == 1  Then
      _Writelog(4, "Splitting Output["&$i&"] or StringReplace  to  result = 1 (No matches found) ")
                        $switch = Not $switch
                        $i += 1
      EndIf
     _Writelog(4, "Splitting Output["&$i &"] or StringReplace  to  result <> 1 (matches found) ")
     EndIf
    EndIf
     _Writelog(4, "String  = "& $switch)
                If $switch Then
     _Writelog(4, "$switch $output["&$i&"]to be split by  = "& $switch)
                    $result = StringRegExp($output[$i], '([0-9.]+%)|([0-9.]+s*[mg]?)s*(.*)', 1)
     _Writelog(4, "split result  = "&$Result)
                    If IsArray($result) Then
                        If StringInStr($result[0], "%") Then; Current line is a progress update line
                        ; Set current progress bar to StringTrimRight($result[0], 1)
       GUICtrlSetData($progress, StringTrimRight($result[0], 1))
       _Writelog(4, "Set file complete percentage to  = "&$result[0])
                        ; Set current progress percent label to $result[0]
                        Else; Current line is a new file line
                        ; Reset progress bar to 0
      _FullProgress($NumFiles)
      _Writelog(4, "New File detected")
      _Writelog(4, "Reset percentage to 0%")
                            GUICtrlSetData($progress, 0)
                        ; Reset progress percent label to "0%"
                        ; Set current file size label to $result[0] (either a number in bytes or something like (4.2 m)
      _Writelog(4, "Setting File size to " & $result[1])
                            GUICtrlSetData($sizeLbl, $result[1])
                        ; Set current file name label to $result[1] (outputted as filename)
      _Writelog(4, "Setting File Name to " & $result[2])
                            GUICtrlSetData($fileLbl, $result[2])
                        EndIf
                    EndIf
                EndIf
            Next
            $output = $output[$output[0]]
  EndIf
WEnd
_Writelog(4, "Copy Process Finished")
_Writelog(4, "Reset percentage to 0%")
GUICtrlSetData($progress, 100)
_Writelog(4, "Set Size Lable to Complete")
GUICtrlSetData($sizeLbl, "Complete")
_Writelog(4, "Setting File Name to Complete")
GUICtrlSetData($fileLbl, "Complete")
GUICtrlSetData($FullProgress, 100)
EndFunc
Func _FullProgress($NumFiles)
_Writelog(1, "The Number of files to be transfered at FullProgress func =  " &$NumFiles)
$PerIncr=_Percentage($NumFiles)
_Writelog(1, "The Percent to Increase = " &$PerIncr)
_Writelog(1, "The Current Percent Level =  " &$FProgress)
$FProgress=Number($PerIncr+$FProgress)
GUICtrlSetData($Fullprogress, $FProgress)
_Writelog(1, "The New Percent Level =  " &$FProgress)
EndFunc
Func _Percentage($NumFiles)
$percent=Number((100)/($NumFiles))
Return $percent

EndFunc
Func _Writelog($logtype, $logMessage)
$Vebose=GUICtrlRead($VerboseLogs)
If $vebose <> 1 Then
If $logType = 1 Then
  _FileWriteLog($AppLogFile, $logMessage)
Else
  sleep(1)
EndIf
Else
If $logType = 1 Then
  _FileWriteLog($AppLogFile, $logMessage)
ElseIf $logType = 2 Then
  _FileWriteLog($CopyLog, $logMessage)
ElseIf $logType = 3 Then
  _FileWriteLog($NoCopyLog, $logMessage)
ElseIf $logType = 4 Then
  _FileWriteLog($ProcessBarLog, $logMessage)
Else
_FileWriteLog($AppLogFile, "Unknown Log Type message - " & $logMessage)
EndIf
EndIf
EndFunc
Func _DisableFormControls()
_FileWriteLog(1, "Disabling the Form Controls")
GUICtrlSetState ( $SourceLabel,$GUI_DISABLE)
GUICtrlSetState ( $SourceBtn,$GUI_DISABLE)
GUICtrlSetState ( $DestLabel,$GUI_DISABLE)
GUICtrlSetState ( $DestBtn,$GUI_DISABLE)
GUICtrlSetState ( $GoBtn,$GUI_DISABLE)
GUICtrlSetState ( $ExitBtn,$GUI_DISABLE)
GUICtrlSetState ( $VerboseLogs,$GUI_DISABLE)
EndFunc
Func _EnableFormControl($Control)
_FileWriteLog(1, "Enabling the Form Controls")
  _FileWriteLog(1, "Enabling the Form Controls - " &$Control)
  GUICtrlSetState( $Control,$GUI_Enable)
EndFunc
Link to comment
Share on other sites

HI CMarshy

You should have started another thread and referenced back to this one as it's getting old.

Nevertheless have a look at my post

I did a lot of work on the command line but never got to the proress bar.

There maybe something in there to help you

Good Luck

John Morrison

Link to comment
Share on other sites

  • 10 months later...

This does not use robocopy.

This script uses AutoIt's DirCopy() and FileCopy() to copy a directory with all its sub-directories and files to another location - with a progress bar window.

This works on my XP.

; Copy from AutoIt installed directory - possibly C:Program FilesAutoIt3SciTEcSnippet
Local $CopyDirFrom = RegRead("HKLMSOFTWAREAutoIt v3AutoIt", "InstallDir") & "SciTEcSnippet"
Local $CopyDirTo = @TempDir & "cSnippet"
Local $avarray, $text, $Pid

$Pid = Run('"' & @ComSpec & '" /c dir "' & $CopyDirFrom & '*.*" /B /O:N', '', @SW_HIDE, 2 + 4)
While 1
    $text &= StdoutRead($Pid, False, False)
    If @error Then ExitLoop
    Sleep(10)
WEnd

$text = StringStripWS($text, 7) ; Remove unwanted @CRLF's
$avarray = StringSplit($text, @CRLF, 0)

ProgressOn("Copy Files Progress", "No. of files left to copy = " & $avarray[0], "0 percent done")
For $i = 0 To $avarray[0]
    If FileGetAttrib($CopyDirFrom & "" & $avarray[$i]) = "D" Then
        DirCopy($CopyDirFrom & "" & $avarray[$i], $CopyDirTo & "" & $avarray[$i], 1)
    Else
        FileCopy($CopyDirFrom & "" & $avarray[$i], $CopyDirTo & "" & $avarray[$i], 9)
    EndIf

    ProgressSet(Round(100 - ($i / $avarray[0] * 100), 1), _
            StringFormat("%4.1f percent done", Round($i / $avarray[0] * 100, 1)), _
            "No. of files left to copy = " & $avarray[0] - $i)
Next
ProgressOff ( )

Local $iBut = MsgBox(4, "Operation Done!", 'Press "Yes" to delete newly created directory in Temp Directory.')
If $iBut = 6 Then FileRecycle($CopyDirTo)

And here it is again using _FileListToArray() instead of the Run(@ComSpec.... routine.

I believe this one to be the faster.

#include <File.au3>

; Copy from AutoIt installed directory - possibly C:Program FilesAutoIt3SciTEcSnippet
Local $CopyDirFrom = RegRead("HKLMSOFTWAREAutoIt v3AutoIt", "InstallDir") & "SciTEcSnippet"
Local $CopyDirTo = @TempDir & "cSnippet"
Local $avarray, $text, $Pid

$avarray = _FileListToArray($CopyDirFrom, "*.*")

ProgressOn("Copy Files Progress", "No. of files left to copy = " & $avarray[0], "0 percent done")
For $i = 0 To $avarray[0]
    If FileGetAttrib($CopyDirFrom & "" & $avarray[$i]) = "D" Then
    DirCopy($CopyDirFrom & "" & $avarray[$i], $CopyDirTo & "" & $avarray[$i], 1)
    Else
    FileCopy($CopyDirFrom & "" & $avarray[$i], $CopyDirTo & "" & $avarray[$i], 9)
    EndIf

    ProgressSet(Round(100 - ($i / $avarray[0] * 100), 1), _
    StringFormat("%4.1f percent done", Round($i / $avarray[0] * 100, 1)), _
    "No. of files left to copy = " & $avarray[0] - $i)
Next
ProgressOff ( )

Local $iBut = MsgBox(4, "Operation Done!", 'Press "Yes" to delete newly created directory in Temp Directory.')
If $iBut = 6 Then FileRecycle($CopyDirTo)
Huge help here! thanks!

I ended up using the first one because the array one wasnt working correctly for me, it said it had to only process one item and just hung.

Any clue how to put a cancel button on this screen? or even a 'time left' label?

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...