Hi everyone.
I need to create a login script that copy a lot of files from a directory
for other.
I've already done one like this but I need to make from a lot of directories
from others.
Here is the script that I'm using now:
fromDir = "c:\1"
toDir = "c:\2"
start = Now()
replaceSize = 0
copySize = 0
deleteSize = 0
noChangeSize = 0
Set fso = CreateObject("Scripting.FileSystemObject")
Set logFile = fso.OpenTextFile("Sincronizacao.log", 8, True)
logFile.WriteLine("")
logFile.WriteLine("Iniciado ................... : " & start)
logFile.WriteLine("Origem ..................... : " & fromDir)
logFile.WriteLine("Destino..................... : " & toDir)
If fso.FolderExists(fromDir) And fso.FolderExists(toDir) Then
Call ReplicateDirectory(fromDir, toDir)
Else
logFile.WriteLine("Erro ...................... : Origem ou Destino
inalcancaveis")
End If
Sub ReplicateDirectory(source, target)
Set targetDir = fso.GetFolder(target)
Set sourceDir = fso.GetFolder(source)
Set targetDirFileList = targetDir.Files
Set sourceDirFileList = sourceDir.Files
Set targetDirFolderList = targetDir.SubFolders
Set sourceDirFolderList = sourceDir.SubFolders
For Each targetFile in targetDirFileList
If fso.FileExists(source & "\" & targetFile.Name) Then
Set sourceFile = fso.GetFile(source & "\" & targetFile.Name)
If targetFile.DateLastModified <> sourceFile.DateLastModified Then
targetFilePath = targetDir.Path & "\" & targetFile.Name
'targetFile.Delete(True)
replaceSize = replaceSize + sourceFile.Size
sourceFile.Copy targetFilePath
Else
noChangeSize = noChangeSize + sourceFile.Size
End If
Else
noChangeSize = noChangeSize + targetFile.Size
'targetFile.Delete()
End If
Next
For Each sourceFile in sourceDirFileList
If Not fso.FileExists(target & "\" & sourceFile.Name) Then
copySize = copySize + sourceFile.Size
sourceFile.Copy targetDir.Path & "\" & sourceFile.Name
End If
Next
'For Each targetFolder in targetDirFolderList
'If Not fso.FolderExists(sourceDir & "\" & targetFolder.Name) Then
'deleteSize = deleteSize + targetFolder.Size
'targetFolder.Delete(True)
'End If
'Next
For Each sourceFolder in sourceDirFolderList
If Not fso.FolderExists(targetDir & "\" & sourceFolder.Name) Then
copySize = copySize + sourceFolder.Size
sourceFolder.Copy(targetDir & "\" & sourceFolder.Name)
Else
Call ReplicateDirectory(sourceFolder.Path, targetDir & "\" &
sourceFolder.Name)
End If
Next
End Sub
finish = Now()
logFile.WriteLine("Arquivos Identicos.......... : " & Round(noChangeSize /
1024 /1024, 1) & " MB")
logFile.WriteLine("Arquivos Apagados........... : " & Round(deleteSize /
1024 /1024, 1) & " MB")
logFile.WriteLine("Sincronizados............... : " & Round(replaceSize /
1024 /1024, 1) & " MB")
logFile.WriteLine("Copiados para o Destino..... : " & Round(copySize / 1024
/1024, 1) & " MB")
logFile.WriteLine("Tempo de execução........... : " & DateDiff("n", start,
finish) & " MIN")
logFile.WriteLine("Total Transferido........... : " & Round((replaceSize +
copySize) / 1024 / 1024, 1) & " MB")
logFile.WriteLine("Finalizado.................. : " & finish)
logFile.Close()
My problem is: Need to sync a lot of Dir's with just one VBS.
Tnks