Page 1 sur 1

[R] Progress bar pendant la copie d'un dossier

Posté : mer. 04 juin 2008 16:45
par dorian
Savez-vous s'il est possible de mettre un Progress bar pendant la copie d'un ou plusieurs dossiers ? Le(s) dossier(s) étant assez volumineux, et pour que l'utilisateur n'est pas l'impression d'un bug logiciel, je pense q'un Progress Bar serait une bonne idée.
J'ai bien cherché, mais je ne vois pas comment exécuter deux fonctions en même temps sans stopper l'une ou l'autre.

Cordialement

Re: [..]Progress bar pendant la copie d'un dossier

Posté : mer. 04 juin 2008 19:35
par jbnh

Code : Tout sélectionner

#include <GUIConstants.au3>

_FileCopy("C:\Users\JB\Desktop\test1","C:\Users\JB\Desktop\test2")

Func _FileCopy($fromFile,$tofile)
    Local $FOF_RESPOND_YES = 16
    Local $FOF_SIMPLEPROGRESS = 256
    $winShell = ObjCreate("shell.application")
    $winShell.namespace($tofile).CopyHere($fromFile,$FOF_RESPOND_YES)
EndFunc
Regarde un peu si ca te convient, ça crée une barre de progression windows.

si tu travailles sous gui, tu peux tres bien mettre:

Code : Tout sélectionner

_FileCopy($sOriginalDir, $sDestDir)
des variables quoi ^^

Re: [..]Progress bar pendant la copie d'un dossier

Posté : mer. 04 juin 2008 20:48
par dorian
Merci beaucoup ça ma bien aidé. Je ne sait pas comment tu as trouvé cela, pourrais-tu m'expliquer un peu ton code si cela ne te dérange pas.
Qu'elle est la ligne qui appelle la barre de progression?

Re: [R]Progress bar pendant la copie d'un dossier

Posté : mer. 04 juin 2008 21:10
par jbnh
Je sais plus trop bien, jette un oeil la dessus.

Re: [R]Progress bar pendant la copie d'un dossier

Posté : ven. 13 juin 2008 09:05
par jujubois
Salut

Est-il possible d'avoir la même chose sans l'option de la fermeture sur la barre de progression ??

et est ce que je peux l adapter pendant la compression avec 7za ?

Code : Tout sélectionner

#include <GUIConstants.au3>
ProgressCopy("C:\Rep1", "D:\Rep2\",1)

Func ProgressCopy($current, $destination, $UseMultiColour=0, $attrib = "-R", $overwrite = 1 ,$Run1 = 0 )

;FirstTimeRun Get original DirSize and set up Gui
If $Run1 = 0 Then
Global $OverallQty, $Overall, $source, $overallpercent, $Progress0Text, $progressbar1, $Progress1Text, $progressbar2, $Progress2Text, $LocalPercent
DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 0)
If not FileExists ($Destination) then DirCreate ($Destination); This is why it was failing, the dir did not exist
$source = $current
If StringRight($current, 1) = '' Then $current = StringTrimRight($current, 1)
If StringRight($destination, 1) <> '' Then $destination = $destination & "\"
$tosearch = $current
$Overall = DirGetSize($tosearch, 1)
$OverallQty = $Overall[1]
Global Const $PrCopyGui = GUICreate("Copie des Fichiers", 420, 100, -1, -1, -1, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)
$Progress0Text = GUICtrlCreateLabel("Veuillez patienter", 10, 5, 400, 20, $SS_LEFTNOWORDWRAP)
$progressbar1 = GUICtrlCreateProgress(10, 20, 400, 20)
GUICtrlSetColor(-1, 32250)
$Progress1Text = GUICtrlCreateLabel("", 10, 44, 400, 20, $SS_LEFTNOWORDWRAP)
$progressbar2 = GUICtrlCreateProgress(10, 60, 400, 20, $PBS_SMOOTH)
$Progress2Text = GUICtrlCreateLabel("", 10, 82, 400, 20, $SS_LEFTNOWORDWRAP)
GUISetFont(10, 600)
;$Progress2Text2 = GUICtrlCreateLabel("", 150, 62, 400, 20)
GUICtrlSetColor(-1, 32250); not working with Windows XP Style if not using windows classic style or dllcall above
GUISetState(@SW_SHOW)
GUICtrlSetData($Progress1Text, "Répertoire de travail " & $tosearch)
$Run1 = 1
EndIf

$Size = DirGetSize($current, 3)
$Qty = $Size[1]
Local $search = FileFindFirstFile($current & "\*.*")
While 1
Dim $file = FileFindNextFile($search)
If @error Or StringLen($file) < 1 Then ExitLoop
If Not StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then
$Qty -= 1
$LocalPercent = 100 - (($Qty / $Size[1]) * 100)
$OverallQty -= 1
$overallpercent = 100 - (($OverallQty / $Overall[1]) * 100)
GUICtrlSetData($Progress0Text, "Progression Totale " & Int($overallpercent) & "% Completer")
GUICtrlSetData($progressbar1, $overallpercent)
GUICtrlSetData($progressbar2, $LocalPercent)
GUICtrlSetData($Progress2Text, "Copie du Fichier " & $file)

If $useMultiColour then
GUICtrlSetColor($Progressbar2, _ChangeColour($LocalPercent))
GUICtrlSetColor($Progressbar1, _ChangeColour($OverallPercent))
EndIf

FileCopy($current & "\" & $file, $destination & StringTrimLeft($current, StringLen($source)) & "\" & $file,$overwrite)
FileSetAttrib($destination & StringTrimLeft($current, StringLen($source)) & "\" & $file, $attrib)
EndIf
If StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then
DirCreate($destination & StringTrimLeft($current, StringLen($source)) & "\" & $file)
FileSetAttrib($destination & StringTrimLeft($current, StringLen($source)) & "\" & $file, $attrib)
GUICtrlSetData($Progress1Text, $current & "\" & $file)
ProgressCopy($current & "\" & $file, $destination, $UseMultiColour, $attrib, $overwrite,1)
EndIf
WEnd
FileClose($search)
;when overall percent = 100 set end gui text, delete gui and reset run1 to 0
If $overallpercent = 100 Then
GUICtrlSetData($Progress0Text, "Progression Totale complètée à 100%")
GUICtrlSetData($progressbar1, 100)
GUICtrlSetData($progressbar2, 100)
GUICtrlSetData($Progress2Text, "Terminer !")
Sleep(2000)
GUIDelete($PRCopyGui)
$Run1 = 0
EndIf
EndFunc ;==>ProgressCopy

Func _ChangeColour($start)

$Redness = Int(255 - ($start / 100 * 512))
If $Redness < 0 Then $Redness = 0

$Greeness = Int(($start / 100 * 512) - 257)
If $Greeness < 0 Then $Greeness = 0

$Blueness = Int(255 - ($Redness + $Greeness))

Return ($Redness * 256 * 256) + ($Greeness * 256) + $Blueness

EndFunc
merci