Copydir mit Progressbar

  • Hallo Zusammen

    Ich bin eigentlich anfänger im Thema AutoIt, habe jedoch schon diverse Optionen versucht, die Progressbar einzubauen.
    Das nachfolgende Script habe ich versucht in meines einzubauen, jedoch ohne erfolg

    Mein Script ist eigentlich ganz simpel und vermutlich nicht Fehlerfrei, für ausführliche Kritik bin ich immer dankbar.


    Mein Script:

    Wie man sieht, geht es mir nur umd die Windows 7 Versionen, XP und Vista wird im gleichen Style vervollständigt.

    Das Verzeichnis das kopiert wird ist etwa 80MB Gross, und dauert etwa 1Minute, je nach Computer


    Danke für Eure Hilfe

    3 Mal editiert, zuletzt von sais (31. Januar 2011 um 19:46) aus folgendem Grund: weitere Frage ist entstanden

  • also dein unteres script läut nicht ,weil includes fehlten , wenn du nicht weiss welche du brauchts schau mal in der
    hilfe und beispielen
    hier geänderter code

    Spoiler anzeigen
    [autoit][/autoit] [autoit][/autoit] [autoit]

    #include <GuiConstantsEx.au3>

    [/autoit] [autoit][/autoit] [autoit]

    #include <GuiStatusBar.au3>

    [/autoit] [autoit][/autoit] [autoit]

    #include <GuiButton.au3>

    [/autoit] [autoit][/autoit] [autoit]

    GUICreate("Betriebssystem wählen", 400, 120, 258, 217)

    [/autoit] [autoit][/autoit] [autoit]

    $WinXP = GUICtrlCreateButton("Windows XP", 0, 10, 100, 50)
    $WinVista = GUICtrlCreateButton("Windows Vista", 100, 10, 100, 50)
    $Win732 = GUICtrlCreateButton("Windows 7 32Bit", 200, 10, 100, 50)
    $Win764 = GUICtrlCreateButton("Windows 7 64Bit", 300, 10, 100, 50)
    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    While 1
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
    ExitLoop

    [/autoit] [autoit][/autoit] [autoit]

    ; Windows XP wird gestartet
    Case $WinXP
    MsgBox(64, "Windows XP", "Windows XP")
    ; Windows Vista wird gestartet
    Case $WinVista
    MsgBox(64, "Windows Vista", "Windows Vista")
    ; Windows 7 -32Bit wird gestartet
    Case $Win732
    MsgBox(64, "Windows 7", "Windows 7 32Bit - Dateien werden kopiert (c.a 1min)", 5)
    Sleep(2500)
    DriveMapAdd ("b:", "\\Imageserver\Installation\Win7\32")
    Sleep(1000)
    DirCreate("C:\Installation")
    DirCopy("b:\", "C:\", 1)
    Sleep(200)
    DriveMapDel ("b:")
    Sleep(300)
    ShellExecute("C:\Installation\go.bat")
    Sleep(300)
    ProcessClose("start.exe")
    ; Windows 7 - 64Bit wird gestartet
    Case $Win764
    MsgBox(64, "Windows 7", "Windows 7 64 Bit", 2)
    Sleep(2500)
    DriveMapAdd ("b:", "\\Imageserver\Installation\Win7\64")
    Sleep(1000)
    DirCreate("C:\Installation")
    DirCopy("b:\", "C:\", 1)
    Sleep(200)
    DriveMapDel ("b:")
    ShellExecute("C:\Installation\go.bat")
    ProcessClose("start.exe")

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Exit
    EndSwitch
    WEnd

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit]


    Copydir mit Progressbar ist aber nicht eingebaut

  • Ja, ich habe nicht das komplette Script eingefügt, nur den Teil um den es wirklich geht.

    Bei mir läuft das Script einwandfrei, zumindest die Funktionen die ich will :)

    Könnt Ihr mir Tipps geben, wie ich die oben genannte Progressbar, oder auch eine andere, einbauen kann?

  • Nutze folgendes für meine Progressbar

    [autoit][/autoit][autoit][/autoit][autoit]

    CopyWithProgress(@DesktopDir, 'C:\temp')

    [/autoit][autoit][/autoit][autoit][/autoit][autoit]

    Func CopyWithProgress($srcDir, $destDir)
    If StringRight($srcDir, 1) = "\" Then $srcDir = StringLeft($srcDir, StringLen($srcDir) - 1)
    If StringRight($destDir, 1) <> "\" Then $destDir = $destDir & "\"
    If Not FileExists($destDir) Then DirCreate($destDir)
    $srcSize = DirGetSize($srcDir, 1)
    $1_percent = $srcSize[0] / 100
    Run(@ComSpec & " /c " & 'XCOPY "'& $srcDir & '" "' & $destDir & '" /D /S /E /V /C /H /R /O /Y', "", @SW_HIDE)
    ProgressOn($programfolder[1], $1_percent & "%", "",(@DesktopWidth - 305),(@DesktopHeight - 163))
    Do
    $destSize = DirGetSize($destDir, 1)
    ProgressSet(Round($destSize[0] / $1_percent, 2), Round($destSize[0] / (1024 * 1024), 2) & " MB of " & Round($srcSize[0] / (1024 * 1024), 2)& " MB copied" & @CRLF _
    & $destSize[1] & " of " & $srcSize[1] & " Files copied." & @CRLF _
    & $destSize[2] & " of " & $srcSize[2] & " Folders copied.", Round($destSize[0] / $1_percent, 0) & "%")
    Sleep(200)
    Until $destSize[0] >= $srcSize[0]
    ProgressOff()
    EndFunc

    [/autoit]

    ----------------------------------------------------------------------------------------------------------------------
    Früher musste man Drachen töten und konnte die Jungfrau heiraten.
    Heute gibt es keine Jungfrauen mehr, man muss den Drachen heiraten!

  • So, entschuldigt die vielfache Bearbeitung der Beträge.

    Das kopieren von lokalen Dateien / Verzeichnissen funktioniert soweit einwandfrei. Mein Problem ist, dass ich ein Netzlaufwerk auf b:\ verbinde und deren gesamten Inhalt sollte unter C: kopiert werden. Führe ich das Script aus, kommt das Resultat siehe Anhang #1

    Verändere die quelle auf "b:\" und das ziel auf "C:\test" wird der Status korrekt angezeigt, jedoch wird nichts kopiert (Der Zielordner wird erstellt)

    Könnt Ihr mir da weiter helfen?


    [autoit]

    #cs ----------------------------------------------------------------------------
    AutoIt Version: 3.3.6.1
    Author: Thomas Inauen
    Script Function:
    - Auswahl des Betriebssystems
    - Windows XP
    - Windows Vista
    - Windows 7 32 Bit
    - Windows 7 64 Bit
    #ce ----------------------------------------------------------------------------
    ;Start
    ; Bibliotheken werden hinzugefügt
    #include <GuiConstantsEx.au3>
    #include <GuiStatusBar.au3>
    #include <GuiButton.au3>
    ; Design wird erstellt
    GUICreate("Betriebssystem wählen - Mein Unternehmen", 500, 70, 158, 217)
    $WinXP = GUICtrlCreateButton("Windows XP", 0, 10, 100, 50)
    $WinVista = GUICtrlCreateButton("Windows Vista", 100, 10, 100, 50)
    $Win732 = GUICtrlCreateButton("Windows 7 32Bit", 200, 10, 100, 50)
    $Win764 = GUICtrlCreateButton("Windows 7 64Bit", 300, 10, 100, 50)
    $Win8 = GUICtrlCreateButton("Windows 8", 400, 10, 100, 50)
    GUISetState(@SW_SHOW)
    ; Script für das kopieren der entsprechenden Dateien
    Func CopyWithProgress($srcDir, $destDir)
    If StringRight($srcDir, 1) = "\" Then $srcDir = StringLeft($srcDir, StringLen($srcDir) - 1)
    If StringRight($destDir, 1) <> "\" Then $destDir = $destDir & "\"
    If Not FileExists($destDir) Then DirCreate($destDir)
    $srcSize = DirGetSize($srcDir, 1)
    $1_percent = $srcSize[0] / 100
    Run(@ComSpec & " /c " & 'XCOPY "'& $srcDir & '" "' & $destDir & '" /D /S /V /C /H /R /O /Y', "", @SW_HIDE)
    ProgressOn("Dateien werden kopiert", $1_percent & "%", "",(@DesktopWidth - 800),(@DesktopHeight - 600))
    Do
    $destSize = DirGetSize($destDir, 1)
    ProgressSet(Round($destSize[0] / $1_percent, 2), Round($destSize[0] / (1024 * 1024), 2) & " MB von " & Round($srcSize[0] / (1024 * 1024), 2)& " MB kopiert" & @CRLF _
    & $destSize[1] & " von " & $srcSize[1] & " Dateien kopiert" & @CRLF _
    & $destSize[2] & " von " & $srcSize[2] & " Ordner kopiert.", Round($destSize[0] / $1_percent, 0) & "%")
    Sleep(200)
    Until $destSize[0] >= $srcSize[0]
    ProgressOff()
    EndFunc
    ; Auswahl wird generiert
    While 1
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
    ExitLoop
    ; Windows XP wird gestartet
    Case $WinXP
    BlockInput(1)
    MsgBox(64, "Windows XP", "Windows XP")
    Sleep(2500)
    DriveMapAdd ("b:", "\\Imageserver\Installation\XP")
    Sleep(100)
    ; Dateien werden kopiert, Fortschritt wird angezeigt
    CopyWithProgress('b:', 'C:')
    Sleep(200)
    DriveMapDel ("b:")
    Sleep(300)
    ShellExecute("C:\Mein Unternehmen\Bildschirmhintergrund CCS\go.bat")
    Sleep(300)
    ProcessClose("start.exe")
    BlockInput(0)
    ; Windows Vista wird gestartet
    Case $WinVista
    BlockInput(1)
    MsgBox(64, "Windows Vista", "Windows Vista")
    Sleep(2500)
    DriveMapAdd ("b:", "\\Imageserver\Installation\Vista")
    Sleep(100)
    ; Dateien werden kopiert, Fortschritt wird angezeigt
    CopyWithProgress('b:\', 'C:\')
    Sleep(200)
    DriveMapDel ("b:")
    Sleep(300)
    ShellExecute("C:\Mein Unternehmen\Bildschirmhintergrund CCS\go.bat")
    Sleep(300)
    ProcessClose("start.exe")
    BlockInput(0)
    ; Windows 7 -32 Bit wird gestartet
    Case $Win732
    BlockInput(1)
    MsgBox(64, "Windows 7", "Windows 7 32Bit", 2)
    Sleep(2500)
    DriveMapAdd ("b:", "\\Imageserver\Installation\Win7\32")
    Sleep(100)
    ; Dateien werden kopiert, Fortschritt wird angezeigt
    CopyWithProgress('b:\', 'C:\test')
    Sleep(200)
    DriveMapDel ("b:")
    Sleep(300)
    ShellExecute("C:\Mein Unternehmen\Bildschirmhintergrund CCS\go.bat")
    Sleep(300)
    ProcessClose("start.exe")
    BlockInput(0)
    ; Windows 7 - 64Bit wird gestartet
    Case $Win764
    BlockInput(1)
    MsgBox(64, "Windows 7", "Windows 7 64 Bit", 2)
    Sleep(2500)
    DriveMapAdd ("b:", "\\Imageserver\Installation\Win7\64")
    Sleep(1000)
    ; Dateien werden kopiert, Fortschritt wird angezeigt
    CopyWithProgress('b:', 'C:')
    Sleep(200)
    DriveMapDel ("b:")
    ShellExecute("C:\Mein Unternehmen\Bildschirmhintergrund CCS\go.bat")
    ProcessClose("start.exe")
    BlockInput(0)
    ; Windows 8 - wird gestartet
    Case $Win8
    BlockInput(1)
    MsgBox(64, "Windows 8", "Windows 8 gibt's noch nicht :)", 2)
    #cs
    Sleep(2500)
    DriveMapAdd ("b:", "\\Imageserver\Installation\Win8")
    Sleep(1000)
    ; Dateien werden kopiert, Fortschritt wird angezeigt
    CopyWithProgress('b:', 'C:')
    Sleep(200)
    DriveMapDel ("b:")
    ShellExecute("C:\Mein Unternehmen\Bildschirmhintergrund CCS\go.bat")
    ProcessClose("start.exe")
    BlockInput(0)
    Exit
    #ce
    EndSwitch
    WEnd

    [/autoit]
  • Hi,

    ich denke der Fehler ist bei XCOPY zu suchen.
    Leider springt die Funktion in die Schleife, ohne zu prüfen, ob XCOPY überhaupt erfolgreich gestartet wurde ...

    Setze das "showflag" erst einmal auf @SW_SHOW um zu sehen was XCOPY macht ...

    Spoiler anzeigen
    [autoit]


    CopyWithProgress (@DesktopDir, 'C:\temp')

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func CopyWithProgress ($srcDir, $destDir)
    If StringRight ($srcDir, 1) == "\" Then $srcDir = StringLeft ($srcDir, StringLen ($srcDir) - 1)
    If StringRight ($destDir, 1) <> "\" Then $destDir = $destDir & "\"
    If Not FileExists ($destDir) Then DirCreate ($destDir)
    $srcSize = DirGetSize ($srcDir, 1)
    $1_percent = $srcSize[0] / 100

    [/autoit] [autoit][/autoit] [autoit]

    ; http://www.microsoft.com/resources/docu…y.mspx?mfr=true
    $ret = ShellExecute ("xcopy", StringFormat ('"%s" "%s" /D /S /E /V /C /H /R /O /Y /Z', $srcDir, $destDir), "", "open", @SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit]

    If ($ret) Then

    [/autoit] [autoit][/autoit] [autoit]

    ProgressOn ($programfolder[1], $1_percent & "%", "",(@DesktopWidth - 305),(@DesktopHeight - 163))
    Do
    $destSize = DirGetSize ($destDir, 1)

    [/autoit] [autoit][/autoit] [autoit]

    ProgressSet ( _
    Round ($destSize[0] / $1_percent, 2), _
    StringFormat ( _
    "%.2f MB von %.2f MB kopiert.\n%d von %d Dateien kopiert.\n%d von %d Ordner kopiert.", _
    $destSize[0] / (1024 * 1024), $srcSize[0] / (1024 * 1024), _
    $destSize[1], $srcSize[1], $destSize[2], $srcSize[2] _
    ), _
    Round ($destSize[0] / $1_percent, 0) & "%" _
    )
    Sleep (200)
    Until $destSize[0] >= $srcSize[0]
    ProgressOff ()
    Else
    ConsoleWrite (StringFormat ("! XCOPY fehlgeschlagen!\n"))
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    EndFunc

    [/autoit]


    Gruß
    Greenhorn