Code : Tout sélectionner
#include <Date.au3>
#include <GUIConstantsEx.au3>
#include <GUIComboBox.au3>
; a modifier: destination, source1, source2, source3 sans le \ de la fin
$destination = ""
$source1 = ""
$source2 = ""
$source3 = ""
$source4 = $destination
$begin = TimerInit() ; debut du timer
;calcul de la date m -1
$aNewDate = StringSplit(_DateAdd( 'm',-1, _NowCalcDate()), "/")
Global $Annee = $aNewDate[1], $Mois = $aNewDate[2], $Jour = $aNewDate[3]
;copie des repertoires avec la xcopy de cmd
Global $Dst = $destination
Global $Src[3] = [$source1, $source2, $source3]
SplashTextOn("Sauvegarde", "Sauvegarde des fichiers modifiés en cours ...", 550, 60, -1, -1, 4, "", 20) ; debut de la sauuvegarde
;formule pour xcopy sous cmd
For $i = 0 to UBound($Src) - 1
$cmd = 'XCOPY "' & $Src[$i] & '\*.*" "' & $Dst & "\" & $annee & "." & $mois & '\*.*" /d:' & $mois & "-01-" & $annee & " /s/c/i/f/y"
RunWait(@ComSpec & " /c " & $cmd, "", @SW_HIDE)
Next
Sleep(1000)
SplashOff() ; fin de sauvegarde
$dif = TimerDiff($begin) ; fin du timer
$min = round($dif/1000/60,0) ; calcul en min du timer
$sec = abs(Round((($dif/1000/60)-$min)*60,0)) ; calcul en second du timer
Global $msg, $deplacer, $explorer, $ok, $lettre, $size
;trouver le nombre d'octect
$size = DirGetSize($destination,1)
$taille = round($size[0]/ 1000000000, 2) ; mettre les octect en Go
$fichier = $size[1] ; trouver le nombre de fichier
$repertoire =$size[2] ; touver le nombre de fchier
;~ creation d'une boite de dialogue
$copie = GUICreate("copie fini", 270, 200) ; fenêtre principale
GUISetState(@SW_SHOW) ; will display an empty dialog box
GUICtrlCreateLabel ("la copie est fini en " & $min & " min" & $sec & " s", 10, 10) ; creation d'un texte
GUICtrlCreateLabel ("taille (Go): " & $taille, 10, 30)
GUICtrlCreateLabel ("nombre de fichier: " & $fichier, 10, 50)
GUICtrlCreateLabel ("nombre de dossier: " & $repertoire, 10, 70)
GUICtrlCreateLabel ("deplacer vers ...", 10, 100)
$lettre = GUICtrlCreateCombo ("", 100, 100, 50)
_GUICtrlComboBox_AddDir($lettre, "", $DDL_DRIVES, False) ; creation d'un combo avec les lecteurs du PC
$deplacer = GUICtrlCreateButton ("deplacer", 160, 100 , 100) ; creation d'un bouton
$explorer = GUICtrlCreateButton ("explorer et quitte", 160, 130, 100)
$ok = GUICtrlCreateButton ("quitte", 160, 160 , 100)
;~ creation des choix de bouton
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
Exit
case $msg = $deplacer
$dst = GUICtrlRead($lettre) ; garde ma lettre (combo) en memoire
$src = $source4
ExitLoop
Case $msg = $explorer
run ("explorer destination")
Exit ; fin du program
Case $msg = $ok
Exit
EndSelect
WEnd
GUIDelete()
;~ EndFunc ;==>Example1
;barrre de progression de windows
Global Const $FO_MOVE = 0x0001
Global Const $FO_COPY = 0x0002
Global Const $FO_DELETE = 0x0003
Global Const $FO_RENAME = 0x0004
Global Const $FOF_MULTIDESTFILES = 0x0001
Global Const $FOF_CONFIRMMOUSE = 0x0002
Global Const $FOF_SILENT = 0x0004
Global Const $FOF_RENAMEONCOLLISION = 0x0008
Global Const $FOF_NOCONFIRMATION = 0x0010
Global Const $FOF_WANTMAPPINGHANDLE = 0x0020
Global Const $FOF_ALLOWUNDO = 0x0040
Global Const $FOF_FILESONLY = 0x0080
Global Const $FOF_SIMPLEPROGRESS = 0x0100
Global Const $FOF_NOCONFIRMMKDIR = 0x0200
Global Const $FOF_NOERRORUI = 0x0400
Global Const $FOF_NOCOPYSECURITYATTRIBS = 0x0800
Global Const $FOF_NORECURSION = 0x1000
Global Const $FOF_NO_CONNECTED_ELEMENTS = 0x2000
Global Const $FOF_WANTNUKEWARNING = 0x4000
Global Const $FOF_NORECURSEREPARSE = 0x8000
; code pour le Deplacement
$n = _ActionWithProgress($Src, $Dst, '', $FO_MOVE)
If Not $n Then ConsoleWrite('error:' & @error & @CRLF)
Func _ActionWithProgress($sFrom, $sTo, $sTitle = '', $sAction = $FO_COPY)
Local $SHFILEOPSTRUCT, $pFrom, $pTo, $pTitle, $aDllRet, $nError = 0
Local $flags = BitOR($FOF_NOCONFIRMMKDIR, $FOF_NOCONFIRMATION, $FOF_NOERRORUI)
$SHFILEOPSTRUCT = DllStructCreate("hwnd hwnd;uint wFunc;ptr pFrom;ptr pTo;int fFlags;int fAnyOperationsAborted;ptr hNameMappings;ptr lpszProgressTitle")
DllStructSetData($SHFILEOPSTRUCT, "hwnd", 0)
DllStructSetData($SHFILEOPSTRUCT, "wFunc", $sAction)
$pFrom = DllStructCreate("char[" & StringLen($sFrom)+2 & "]")
DllStructSetData($pFrom, 1, $sFrom)
DllStructSetData($pFrom, 1, Chr(0), StringLen($sFrom)+2) ; second null at the end
DllStructSetData($SHFILEOPSTRUCT, "pFrom", DllStructGetPtr($pFrom))
$pTo = DllStructCreate("char[" & StringLen($sTo)+2 & "]")
DllStructSetData($pTo, 1, $sTo)
DllStructSetData($pTo, 1, Chr(0), StringLen($sTo)+2) ; second null at the end
DllStructSetData($SHFILEOPSTRUCT, "pTo", DllStructGetPtr($pTo))
DllStructSetData($SHFILEOPSTRUCT, "fAnyOperationsAborted", 0)
DllStructSetData($SHFILEOPSTRUCT, "hNameMappings", 0)
If $sTitle <> '' Then
$pTitle = DllStructCreate("char[" & StringLen($sTitle)+1 & "]")
;$pTitle = DllStructCreate("char[4]")
DllStructSetData($pTitle, 1, $sTitle)
;DllStructSetData($pTitle, 1, 'aaa')
DllStructSetData($pTitle, 1, Chr(0), StringLen($sTitle)+1) ; null at the end
$flags = BitOR($flags, $FOF_SIMPLEPROGRESS)
DllStructSetData($SHFILEOPSTRUCT, "lpszProgressTitle", DllStructGetPtr($pTitle))
;~ DllStructSetData($SHFILEOPSTRUCT, "lpszProgressTitle", 'aaa')
Else
DllStructSetData($SHFILEOPSTRUCT, "lpszProgressTitle", 0)
EndIf
DllStructSetData($SHFILEOPSTRUCT, "fFlags", $flags)
$aDllRet = DllCall("shell32.dll", "int", "SHFileOperation", "ptr", DllStructGetPtr($SHFILEOPSTRUCT))
If @error Or $aDllRet[0] <> 0 Then
$aDllRet = DllCall("kernel32.dll", "long", "GetLastError")
If Not @error Then $nError = $aDllRet[0]
EndIf
; test if button Abort was pressed
If DllStructGetData($SHFILEOPSTRUCT, "fAnyOperationsAborted") Then $nError = -1
$pFrom = 0
$pTo = 0
$pTitle = 0
$SHFILEOPSTRUCT = 0
If $nError <> 0 Then
SetError($nError)
Return False
EndIf
Return True
EndFunc
; fin de la barre de windows