Page 1 sur 1

Barre de progression avec DirCopy

Posté : ven. 07 juin 2019 15:42
par Wiltech
Bonjour,
j’essaye depuis un bon moment de faire une barre de progression pour qu'on puisse voir l'avancer de la copie d'un dossier, j'ai trouver sur le forum un code mais je n'arrive pas à l'adapté pour moi :evil:

_DirCopy($localisation[1],$localisationUSB&"\"&$nameFolder)

Func _DirCopy($source, $dest)
    $oShell = ObjCreate("shell.application")
    $Shell = $oShell.namespace($dest)
   $Shell.copyHere($source,256)  ; 256 = affiche la progressbar de windows
EndFunc
 
Il m'affiche à chaque fois l'erreur :

Code : Tout sélectionner

"C:\Users\test\Documents\Autoit_Final\Get_Driver\Get_Driver.au3" (52) : ==> Subscript used on non-accessible variable.:
_DirCopy($localisation[1],$localisationUSB&"\"&$nameFolder)
_DirCopy($localisation^ ERROR
Merci a tous ceux qui m'aiderons :D

Re: Barre de progression avec DirCopy

Posté : ven. 07 juin 2019 15:49
par Tlem
D'après ce que vous donnez comme infos, $localisation[1] n'est pas une valeur de tableau.
Modifiez l'appel de fonction avec des valeurs valides et cela fonctionnera. ^^

Re: Barre de progression avec DirCopy

Posté : ven. 07 juin 2019 15:58
par Wiltech
D'après ce que vous donnez comme infos, $localisation[1] n'est pas une valeur de tableau.
Modifiez l'appel de fonction avec des valeurs valides et cela fonctionnera. ^^
Désoler j'avait mal exécuter mon script ce n'est pas cette erreur qu'il m'affiche mais celle-ci :

Code : Tout sélectionner

"C:\Users\Nicolas\Documents\Autoit_Final\Get_Driver\Get_Driver.au3" (74) : ==> The requested action with this object has failed.:
$Shell.copyHere($source,256)
$Shell^ ERROR

Re: Barre de progression avec DirCopy

Posté : ven. 07 juin 2019 22:41
par Tlem
La fonction semble incorrecte. Celle-ci fonctionne :

Code : Tout sélectionner

Func _DirCopy2($source, $dest)
    $oShell = ObjCreate("shell.application")
    $oShell.namespace($dest).copyHere($source,256)  ; 256 = affiche la progressbar de windows
EndFunc
Ceci-dit, il serait très certainement préférable d'utiliser cell ci-dessous qui est bien plus complète et qui prends en charge la destination inexistante. ^^

Code : Tout sélectionner

;===============================================================================
;
; Function Name:    _FileCopy()
; Description:      Copies Files and/or Folders with optional animated Windows dialog box
; Parameter(s):     $pFrom - Source files/folders to copy from
;                           $pTo - Destination folder to copy to
;                           $fFlags - [optional] Defines the flag for CopyHere action
;
; Option Flags:        $FOF_DEFAULT = 0          Default. No options specified.
;                       $FOF_SILENT = 4              Do not display a progress dialog box.
;                       $FOF_RENAMEONCOLLISION = 8 Rename the target file if a file exists at the target location with the same name.
;                       $FOF_NOCONFIRMATION = 16    Click "Yes to All" in any dialog box displayed.
;                       $FOF_ALLOWUNDO = 64          Preserve undo information, if possible.
;                       $FOF_FILESONLY = 128          Perform the operation only if a wildcard file name (*.*) is specified.
;                       $FOF_SIMPLEPROGRESS = 256   Display a progress dialog box but do not show the file names.
;                       $FOF_NOCONFIRMMKDIR = 512   Do not confirm the creation of a new directory if the operation requires one to be created.
;                       $FOF_NOERRORUI = 1024          Do not display a user interface if an error occurs.
;                       $FOF_NORECURSION = 4096     Disable recursion.
;                       $FOF_SELECTFILES = 9182 Do not copy connected files as a group. Only copy the specified files.
;
; Requirement(s):   None.
; Return Value(s):  No return values per MSDN article.
; Author(s):        Jos, commented & modified by ssubirias3 to create $pTo if not present
; Note(s):          Must declare $fFlag variables or use their numeric equivalents without declaration. Use BitOR() to combine
;                       Flags. See http://support.microsoft.com/kb/151799 &
;                       http://msdn2.microsoft.com/en-us/library/ms723207.aspx for more details
;
;===============================================================================
Func _FileCopy($pFrom, $pTo, $fFlags = 0)
    Local $FOF_NOCONFIRMMKDIR = 512
    Local $FOF_NOCONFIRMATION = 16
    If Not FileExists($pTo) Then DirCreate($pTo)
    $winShell = ObjCreate("shell.application")
    $winShell.namespace($pTo).CopyHere($pFrom, BitOR($FOF_NOCONFIRMMKDIR,$FOF_NOCONFIRMATION))
EndFunc
Source