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.
@+ :)