SynchronizeDirectoryTrees – Synchronize files in two directory trees

SynchronizeDirectoryTrees – Synchronize files in two directory trees

' Synchronize two directory subtrees'' This routine compares source and dest directory trees and copies files' from source that are newer than (or are missing in) the destination directory' if TWOWAYSYNC is True, files are synchronized in both ways' NOTE: requires the CompareDirectories and SynchronizeDirectories routines'       and a reference to the Microsoft Scripting Runtime type librarySub SynchronizeDirectoryTrees(ByVal sourceDir As String, _    ByVal destDir As String, Optional ByVal TwoWaySync As Boolean)    Dim fso As New Scripting.FileSystemObject    Dim sourceFld As Scripting.Folder    Dim destFld As Scripting.Folder    Dim fld As Scripting.Folder    Dim col As New Collection        ' we need this in case the dest subdir doesn't exist    On Error Resume Next        ' get reference to source and dest folder objects    Set sourceFld = fso.GetFolder(sourceDir)    Set destFld = fso.GetFolder(destDir)    ' create the destination directory, if necessary    If Err Then        ' if the destination directory doesn't exist,        '  create it and copy all files there        ' (this is all we need)        fso.CopyFolder sourceDir, destDir        ' nothing else to do        Exit Sub    End If        ' synchronize the root directories    SynchronizeDirectories sourceDir, destDir, TwoWaySync        ' ensure that dir names have a training backslash    If Right$(sourceDir, 1) <> "" Then sourceDir = sourceDir & ""    If Right$(destDir, 1) <> "" Then destDir = destDir & ""        ' repeat for all the subdirectories in the source directory    For Each fld In sourceFld.SubFolders        ' remember that we have processed this subdir        col.Add fld.Name, fld.Name                ' call this routine recursively        SynchronizeDirectoryTrees fld.Path, destDir & fld.Name, TwoWaySync    Next        ' if two-way synchronization was requested, ensure that all subdirs in dest    ' directories are copied into source directory    If TwoWaySync Then        For Each fld In destFld.SubFolders            If col(fld.Name) = "" Then                ' we get here only if the folder name isn't in COL,                '  and therefore                ' if this subdirectory isn't in the source directory                fso.CopyFolder fld.Path, sourceDir & fld.Name            End If        Next    End IfEnd Sub

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes

ransomware cyber attack

Why Is Ransomware Such a Major Threat?

One of the most significant cyber threats faced by modern organizations is a ransomware attack. Ransomware attacks have grown in both sophistication and frequency over the past few years, forcing