Jump to content

mulitple file & folder progress bar


butcha
 Share

Recommended Posts

Hi,

I'm sure loads of progress bars have been done in the past but I seem to struggle understanding the code and getting it to actually work

see below my code I have at the moment and I would like to attach a progress bar once copy files has been clicked o n the form, but not sure how to do it.

I even look at copyhere method but the wont be good if files already exist (I have only the option to overwrite rather than check last modified date)

hope this makes sense

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=H:\Autoit\Forms\epack.kxf
$Form1 = GUICreate("E-Pack Copy for Citrix", 223, 295, 192, 133)
GUISetIcon("H:\Misc\mblogo.ico")
$Label1 = GUICtrlCreateLabel("Select the servers to", 8, 8, 146, 20)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("copy the E-Pack files to:", 8, 25, 171, 20)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Button1 = GUICtrlCreateButton("Select All", 128, 80, 89, 25, $WS_GROUP)
GUICtrlSetTip(-1, "Select all Citrix servers")
$Button2 = GUICtrlCreateButton("Clear All", 128, 112, 89, 25, $WS_GROUP)
GUICtrlSetTip(-1, "Clear all selected Citrix servers")
$Button3 = GUICtrlCreateButton("Copy Files", 128, 176, 89, 65, $WS_GROUP)
GUICtrlSetTip(-1, "Copy EPack files to the selected servers")
$Button4 = GUICtrlCreateButton("Exit", 128, 144, 89, 25, $WS_GROUP)
GUICtrlSetTip(-1, "Live Citrix Presentation Server")
GUICtrlSetCursor (-1, 0)
GUICtrlSetTip(-1, "Live Citrix Presentation Server")
GUICtrlSetCursor (-1, 0)
GUICtrlSetTip(-1, "Live Citrix Presentation Server")
GUICtrlSetCursor (-1, 0)
GUICtrlSetTip(-1, "Live Citrix Presentation Server")
GUICtrlSetCursor (-1, 0)
GUICtrlSetTip(-1, "DR Citrix Presentation Server")
GUICtrlSetCursor (-1, 0)
GUICtrlSetTip(-1, "DR Citrix Presentation Server")
GUICtrlSetCursor (-1, 0)
GUICtrlSetTip(-1, "User Acceptance Testing Citrix Presentation Server")
GUICtrlSetCursor (-1, 0)
GUICtrlSetTip(-1, "Development Citrix Presentation Server")
GUICtrlSetCursor (-1, 0)
$Progress1 = GUICtrlCreateProgress(8, 256, 201, 25)
$Button5 = GUICtrlCreateButton("Please Read", 128, 48, 89, 25, $WS_GROUP)
$Label3 = GUICtrlCreateLabel("Copy Progress. . .", 8, 240, 87, 17)
dim $checkbox[8]
$checkbox[0] = GUICtrlCreateCheckbox("LonCtxPS1", 8, 48, 81, 17)
$checkbox[1] = GUICtrlCreateCheckbox("LonCtxPS2", 8, 72, 81, 17)
$checkbox[2] = GUICtrlCreateCheckbox("LonCtxPS3", 8, 96, 81, 17)
$checkbox[3] = GUICtrlCreateCheckbox("LonCtxPS4", 8, 120, 81, 17)
$checkbox[4] = GUICtrlCreateCheckbox("PetCtxPS1", 8, 144, 81, 17)
$checkbox[5] = GUICtrlCreateCheckbox("PetCtxPS2", 8, 168, 81, 17)
$checkbox[6] = GUICtrlCreateCheckbox("UATCtxPS1", 8, 192, 81, 17)
$checkbox[7] = GUICtrlCreateCheckbox("DEVCtxPS1", 8, 216, 81, 17)

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

While 1
$nMsg = GUIGetMsg()

Select
Case $nMsg = $GUI_EVENT_CLOSE
Exit
        Case $nMsg = $Button1   ;Check All
            For $n = 0 To UBound($checkbox) - 1
            ;For $n = 0 To 7 Step 1
                GUICtrlSetState ( $checkbox[$n] , $GUI_CHECKED )
            Next

        case $nmsg = $Button2   ;Clear All
            For $n = 0 To UBound($checkbox) - 1
            ;For $n = 0 To 7 Step 1
                GUICtrlSetState ( $checkbox[$n] , $GUI_UNCHECKED )
            Next

        case $nmsg = $Button3   ;Copy Files

$fSelection = False
For $n = 0 To UBound($checkbox) - 1
    If BitAND(GUICtrlRead($checkbox[$n]), $GUI_CHECKED) Then
        $fSelection = True
        ExitLoop
    EndIf
Next

If $fSelection Then
    $answer = msgBox(36, 'Copy Files to Citrix servers', 'Are you sure you want to copy E-Packs files to the selected servers?')
        if $answer = 6 then
            $status1 = GUICtrlRead($checkbox[0])
            $status2 = GUICtrlRead($checkbox[1])
            $status3 = GUICtrlRead($checkbox[2])
            $status4 = GUICtrlRead($checkbox[3])
            $status5 = GUICtrlRead($checkbox[4])
            $status6 = GUICtrlRead($checkbox[5])
            $status7 = GUICtrlRead($checkbox[6])
            $status8 = GUICtrlRead($checkbox[7])

            If $status1 = 1 then call ("o1copy")
            If $status2 = 1 then call ("o2copy")
            If $status3 = 1 then call ("o3copy")
            If $status4 = 1 then call ("o4copy")
            If $status5 = 1 then call ("o5copy")
            If $status6 = 1 then call ("o6copy")
        endif
        if $answer = 7 Then
        EndIf
Else
    MsgBox(48, 'No Items Selected', 'You have not selected any Citrix servers to copy E-Pack files to, Please select from the list')
EndIf

                case $nmsg = $Button4
        Exit

        case $nmsg = $Button5
            MsgBox(64, 'Please Read. . .', '1. You need to be logged in with your admin account on the network.' & @CRLF & @CRLF & '2. Epack Files need to be located in'& @CRLF & '    \\ad.saffery.net\saffery\IT\Rollout\Software\CaseWare\Updates')

EndSelect

WEnd

;Functions for copying files
Func o1copy()
    DirCopy("C:\Temp\test\1", "C:\Temp\end", 1)
EndFunc

Func o2copy()
    DirCopy("C:\Temp\test\2", "C:\Temp\end", 1)
EndFunc

Func o3copy()
    DirCopy("C:\Temp\test\3", "C:\Temp\end", 1)
EndFunc

Func o4copy()
    DirCopy("C:\Temp\test\4", "C:\Temp\end", 1)
EndFunc

Func o5copy()
    DirCopy("C:\Temp\test\5", "C:\Temp\end", 1)
EndFunc

Func o6copy()
    DirCopy("C:\Temp\test\6", "C:\Temp\end", 1)
EndFunc

many thanks in advance

Link to comment
Share on other sites

In the loop where you are testing if anything is checked, don't exit the loop. Check them all and add up either a file count or the file sizes for a simple naive progress calculation.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

In the loop where you are testing if anything is checked, don't exit the loop. Check them all and add up either a file count or the file sizes for a simple naive progress calculation.

:)

Sorry to sound stupid, but could someone show me how it is done, I dont seem to fully understand this yet, (I'm trying tho!!)

many thanks

Link to comment
Share on other sites

Something like this:

; ...

; Array of file names to match up with checkboxes
Global $aFileNames[6] = ["C:\Temp\test\1", "C:\Temp\test\2", "C:\Temp\test\3", _
        "C:\Temp\test\4", "C:\Temp\test\5", "C:\Temp\test\6"]

    ; Case $nMsg = $Button3 ;Copy Files
    $iSelectionCount = 0
    $iSelectionSize = 0
    For $n = 0 To UBound($checkbox) - 1
        If BitAND(GUICtrlRead($checkbox[$n]), $GUI_CHECKED) Then
            $iSelectionCount += 1
            $iSelectionSize += FileGetSize($aFileNames[$n])
        EndIf
    Next

    If $iSelectionSize Then
        $answer = MsgBox(36, 'Copy Files to Citrix servers', _
                'Are you sure you want to copy ' & $iSelectionCount & ' E-Packs files' & @CRLF & _
                '(' & $iSelectionSize & ' bytes total) to the selected servers?')
        If $answer = 6 Then
            $iFileNum = 0
            ProgressOn("Copying E-Packs", "Copying " & $iSelectionCount & " files", "0% Complete")
            For $n = 0 To UBound($checkbox) - 1
                If BitAND(GUICtrlRead($checkbox[$n]), $GUI_CHECKED) Then
                    $iFileNum += 1
                    ProgressSet(($iFileNum - 1) / $iSelectionCount * 100, "Copying " & $iFileNum & " of " & $iSelectionCount)
                    _Copy($aFileNames[$n])
                    ProgressSet($iFileNum / $iSelectionCount * 100)
                EndIf
            Next
        EndIf
    Else
        MsgBox(48, 'No Items Selected', 'You have not selected any ...')
    EndIf

; ...


;Functions for copying files
Func _copy($sFile)
    DirCopy($sFile, "C:\Temp\end", 1)
EndFunc   ;==>_copy

This uses an array of file names that match up with the array of checkboxes to avoid the goofy bunch of Call()s you had.

The percentage in the progress bar here is based on simple file count. You can update it to use file sizes copied / total file size.

Note that the progress is not updated during each actual file copy, just before/after each copy. There are more advanced techniques to use a File System Object (FSO) and get a file copy with progress. Search for examples on the forum if you fell ready to go there.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...