Sub test()
Dim Source As String, NewName As String, Destination As String, copie As Boolean
Source = "C:\Users\patricktoulon\Desktop\dossiertesticon"
NewName = "toto"
Destination = "F:\Repertoire\A\1\" & NewName
'copie = CopyFolderAddAttrSystem2(Destination, Source)
copie = CopyFolderAddAttrSystem2(Destination, Source, True) 'avec pause sur la fenêtre cmd pour lire le log
MsgBox copie
End Sub
Function CopyFolderAddAttrSystem2(ByVal Destination As String, ByVal Source As String, Optional ByVal Log As Boolean = False) As Boolean
Dim cmd$, Wshell As Object, returnBool
Set Wshell = CreateObject("WScript.Shell")
' mkdir sans test (puisque n'écrase pas )
Wshell.Run "cmd /c mkdir """ & Destination & """", 0, True
'commande robocopy [DAT]
' D = Data :le contenu du fichier
' A :Attributes les attributs (lecture seule, caché, système, archive…)
' T : Timestamps les dates (création, modification, accès)
cmd = "cmd /c robocopy """ & Source & """ """ & Destination & """ /E /COPY:DAT /R:0 /W:0" & IIf(Log, " & pause", "")
returnBool = Wshell.Run(cmd, 1, True)
CopyFolderAddAttrSystem2 = (returnBool < 8) ' return de robocopy
End Function