Visual Basic: Copier le contenu d'un dossier vers un autre

bigcheek Messages postés 15 Date d'inscription jeudi 30 mai 2002 Statut Membre Dernière intervention 18 octobre 2007 - 30 mai 2002 à 10:03
bigcheek Messages postés 15 Date d'inscription jeudi 30 mai 2002 Statut Membre Dernière intervention 18 octobre 2007 - 31 mai 2002 à 16:50
Bonjour,

Je suis un novice en programmation et j'aimerais pouvoir donner le choix à l'utilisateur de sauvegarder le contenu d'un dossier qu'il aura choisi dans une "DirListBox"

J'aimerais aussi savoir comment ce même utilisateur pourrait restaurer le contenu d'un dossier dans un autre.

Merci d'avance pour votre aide

2 réponses

DragonDo Messages postés 93 Date d'inscription lundi 8 avril 2002 Statut Membre Dernière intervention 22 juillet 2006
31 mai 2002 à 09:16
Mon projet comporte une Form, une DirlistBox, un Label, un commandbutton

---- Code à insérer dans la partie déclaration de la form
Option Explicit

Private Type SHFILEOPSTRUCT
        hwnd As Long
        wFunc As Long
        pFrom As String
        pTo As String
        fFlags As Integer
        fAnyOperationsAborted As Long
        hNameMappings As Long
        lpszProgressTitle As String '  only used if FOF_SIMPLEPROGRESS
End Type

Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long

Private Const FOF_RENAMEONCOLLISION = &H8
Private Const FOF_NOCONFIRMATION = &H10
Private Const FOF_MULTIDESTFILES = &H1

'----- Début de le procédure de copie
Public Sub CopieFic(ROri As String, Rdest As String, NFlag As Long)

    Dim ShFileOp As SHFILEOPSTRUCT
    Dim Dl As Long
    
    If Left$(ROri, 1) = vbNullChar Then
        Exit Sub
    End If
    
    With ShFileOp
        .hwnd = Me.hwnd
        .wFunc = &H2
        .pFrom = ROri
        .pTo = Rdest
        .fFlags = &H40 Or NFlag
        .lpszProgressTitle = "Sauvegarde des fichiers..."
    End With
    Dl = SHFileOperation(ShFileOp)

End Sub
'----- Fin de la procédure


---- Code a insérer dans CommandButton
Private Sub Command1_Click()

    CopieFic Label1 + vbNullChar + vbNullChar, "c:\temp\Testdomi" + vbNullChar + vbNullChar, 0
    
End Sub


---- Code a insérer dans DirListBox
Private Sub Dir1_Change()

    Label1 = Dir1.List(Dir1.ListIndex)
    
End Sub


Voilà, Le code fonctionne, je l'ai testé chez moi en VB5 et Windows XP.

@+ :)
0
bigcheek Messages postés 15 Date d'inscription jeudi 30 mai 2002 Statut Membre Dernière intervention 18 octobre 2007
31 mai 2002 à 16:50
0
Rejoignez-nous