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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| Function FindFile(ByVal sFol As String, sFile As String)
Dim tFld As Folder
Dim FileName As String
Dim FileVerif As String
Dim FileTrouve As String
Dim Pos As Long
Set fld = fso.GetFolder(sFol)
FileName = Dir(fso.BuildPath(fld.Path, sFile), vbNormal Or vbHidden Or vbSystem Or vbReadOnly)
While Len(FileName) <> 0
FileTrouve = fso.BuildPath(fld.Path, FileName)
Pos = Len(ValRep1)
FileVerif = ValRep2 & Right(FileTrouve, Len(FileTrouve) - Pos)
If FileExist(FileVerif) = False Then
CopyFile FileTrouve, FileVerif, 0
Else
If FileDateTime(FileTrouve) > FileDateTime(FileVerif) Then
CopyFile FileTrouve, FileVerif, 0
End If
End If
FileName = Dir() ' Get next file
DoEvents
Wend
If fld.SubFolders.Count > 0 Then
For Each tFld In fld.SubFolders
Pos = Len(ValRep1)
If DirectoryExist(ValRep2 & Right(tFld, Len(tFld) - Pos)) = False Then
MkDir ValRep2 & Right(tFld, Len(tFld) - Pos)
End If
DoEvents
FindFile = FindFile + FindFile(tFld.Path, sFile)
Next
End If
End Function |
Partager