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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| '====================================================
'CREATION ARBORESCENCE
'====================================================
Option Explicit
Dim ofso,fso,PWD
Set ofso = CreateObject("Scripting.FileSystemObject")
Set fso = CreateObject("Scripting.FileSystemObject")
PWD = Left(WScript.ScriptFullName,(Len(WScript.ScriptFullName) - (Len(WScript.ScriptName) + 1)))
CreerRep (PWD &"\Source") 'determiner ici l'arbo à créer ou les arbo à creer
CreerRep (PWD &"\Destination")
Sub CreerRep (Chemin)
If Not ofso.FolderExists(Chemin) Then
CreerRep(ofso.GetParentFolderName(chemin))
ofso.CreateFolder(chemin)
End if
End Sub
'==============================================================
'COPIE DES FICHIER
'==============================================================
'Copie les fichiers si ils n'existent pas dans le dossier de destination
Dim WshShell
Dim fso1
Dim srcPath
Dim tgtPath
Dim PWD2
On Error Resume Next
Set WshShell = WScript.CreateObject("Wscript.Shell")
Set fso1 = WScript.CreateObject("Scripting.FilesystemObject")
PWD2 = Left(WScript.ScriptFullName,(Len(WScript.ScriptFullName) - (Len(WScript.ScriptName) + 1)))
srcPath = ""& PWD2 &"\Source\"
tgtPath = ""& PWD2 &"\Destination\"
If Not fso1.FileExists(tgtPath) Then
fso1.CopyFile srcPath, tgtPath, True
ElseIf fso1.FileExists(srcPath) Then
ReplaceIfNewer srcPath, tgtPath
End If
MsgBox(""& PWD2 &"\Source\")
MsgBox(""& PWD2 &"\Destination\")
'Copie les fichiers si ils sont plus recents dans destination
Sub ReplaceIfNewer(strSourceFile, strTargetFile)
Const OVERWRITE_EXISTING = True
Dim objFso1
Dim objTargetFile
Dim dtmTargetDate
Dim objSourceFile
Dim dtmSourceDate
Set objFso1 = WScript.CreateObject("Scripting.FileSystemObject")
Set objTargetFile = objFso1.GetFile(strTargetFile)
dtmTargetDate = objTargetFile.DateLastModified
Set objSourceFile = objFso1.GetFile(strSourceFile)
dtmSourceDate = objSourceFile.DateLastModified
If (dtmTargetDate < dtmSourceDate) Then
objFso1.CopyFile objSourceFile.Path, objTargetFile.Path,OVERWRITE_EXISTING
End If
Set objFso1 = Nothing
End Sub |
Partager