SynchronizeDirectories – Synchronize the contents of two directories

SynchronizeDirectories – Synchronize the contents of two directories

' Synchronize two directories'' This routine compares source and dest directories 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 routine and a reference to'       the Microsoft Scripting Runtime type librarySub SynchronizeDirectories(ByVal sourceDir As String, ByVal destDir As String, _    Optional ByVal TwoWaySync As Boolean)    Dim fso As New Scripting.FileSystemObject    Dim index As Long    Dim copyDirection As Integer    ' 1=from source dir, 2=from dest dir,                                    '  0=don't copy        ' retrieve name of files in both directories    Dim arr() As Variant    arr = CompareDirectories(sourceDir, destDir)        ' ensure that both dir names have a trailing backslash    If Right$(sourceDir, 1) <> "" Then sourceDir = sourceDir & ""    If Right$(destDir, 1) <> "" Then destDir = destDir & ""        For index = 1 To UBound(arr, 2)        ' assume this file doesn't need to be copied        copyDirection = 0                ' see whether files are        Select Case arr(1, index)            Case cdeEqual                ' this file is the same in both directories            Case cdeSourceDirOnly                ' this file exists only in source directory                copyDirection = 1            Case cdeDestDirOnly                ' this file exists only in destination directory                copyDirection = 2            Case Else                If arr(1, index) = cdeAttributesDiffer Then                    ' ignore files that differ only for their attributes                ElseIf (arr(1, index) And cdeDateDiffer) = cdeSourceIsOlder Then                    ' file in destination directory is newer                    copyDirection = 2                Else                    ' in all other cases file in source dir should be copied                     ' into dest dire                    copyDirection = 1                End If        End Select                If copyDirection = 1 Then            ' copy from source dir to destination dir            fso.CopyFile sourceDir & arr(0, index), destDir & arr(0, index), _                True        ElseIf copyDirection = 2 And TwoWaySync Then            ' copy from destination dir to source dir            ' (only if two-way synchronization has been requested)            fso.CopyFile destDir & arr(0, index), sourceDir & arr(0, index), _                True        End If    NextEnd Sub

Share the Post:
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

data dictionary

Tools You Need to Make a Data Dictionary

Data dictionaries are crucial for organizations of all sizes that deal with large amounts of data. they are centralized repositories of all the data in organizations, including metadata such as