1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| Option Explicit
Dim fso, Fold, subFold, NewLocation, WshNet, User, FL, newFold
Set WshNet = CreateObject("WScript.Network")
User = WshNet.Username
Set fso = CreateObject("Scripting.FileSystemObject")
NewLocation = "\\server\migration\" & User & "\"
Set Fold = fso.GetFolder("C:\")
For Each subFold in Fold.SubFolders
If InStr(LCase(subFold.Name), "donnees") > 0 Then
VerifDestFolder NewLocation & subFold.Name
For Each FL In subFold.Files ' on parcourt les fichiers dans chaque dossier
If Not fso.FileExists(NewLocation & subFold.Name & "\" & FL.Name) Then
FL.Copy NewLocation & subFold.Name & "\" & FL.Name
End If
Next
End If
Next
' ======== Vérification de l'existence du dossier sinon le créer =========
Sub VerifDestFolder(strFold)
If Not fso.FolderExists(strFold) Then
Set newFold = fso.CreateFolder(strFold)
Else
Exit Sub
End If
End Sub |
Partager