daniel-12 | Bonsoir
je cherche une solution pour synchroniser 2 répertoires
le premier sur C:monrepsource....
le second sur un serveur T:monrepdestination pour la destination je préfère que le script accepte \servermonrepdestination car tous les utilisateurs non pas forcément la même lettre
je voudrais que ce soit automatique pour que je puisse le lancer via des taches planifiées, donc exit les vbs qui me demande la source et destination
et il faudrait aussi que les sous-répertoire soit pris en compte
quelqu'un a cela, en VBS ou VBA ?
j'ai trouvé celui ci, mais il tourne en boucle, écrit et ré-efface
mais j'ai 30go, donc ca va pas le faire sans adaptation
Code :
- 'Synchronizes one folder to another using the xcopy command.
- 'INSTRUCTIONS: Copy FolderSync.vbs to the Startup menu in Windows.
- ' Set SourceFolder to reference the location on your computer.
- ' Set TargetFolder to reference the location to copy files to.
- ' Adjust scan time to a desired level. 3 seconds (3000) is default.
- ' More time may reduce system lag or HDD lag, less time will make
- ' files more quickly available.
- Dim SourceFolder: SourceFolder = "F:DCIM"
- Dim TargetFolder: TargetFolder = "H:" '\servershare also works
- Dim ScanTime: ScanTime = 3000
- 'Do not edit
- Dim retval: retval = 0
- Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject" )
- Set wshShell = WScript.CreateObject ("WSCript.shell" )
- While retval = 0
- retval = wshshell.run("%windir%system32xcopy.exe """&SourceFolder&"*.*"" """&TargetFolder&""" /d /y /s", 0, True)
- CheckDeletions TargetFolder,TargetFolder, SourceFolder
- WScript.Sleep(ScanTime) 'milleseconds
- Wend
- set wshshell = Nothing 'it will never get here.
- Sub CheckDeletions(Target, TargetFolder, SourceFolder)
- Set Folder = objFSO.GetFolder(Target)
- 'check if source folder exists
- If Not objFSO.FolderExists(Replace(Folder.Path,TargetFolder,SourceFolder)) Then
- Folder.Delete True 'delete folder because it doesn't exist in the source
- Else 'check within the folder
- For Each Subfolder in Folder.SubFolders
- CheckDeletions Subfolder.Path,TargetFolder,SourceFolder
- Next
- 'get the files in the folder
- Set colFiles = Folder.Files
- For Each objFile in colFiles
- If Not objFSO.FileExists(Replace(objFile.Path,TargetFolder,SourceFolder)) Then
- objFile.Delete True 'delete file because it doesn't exist in the source
- End If
- Next
- End If
- End Sub
|
|