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:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

iOS app development

The Future of iOS App Development: Trends to Watch

When it launched in 2008, the Apple App Store only had 500 apps available. By the first quarter of 2022, the store had about 2.18 million iOS-exclusive apps. Average monthly app releases for the platform reached 34,000 in the first half of 2022, indicating rapid growth in iOS app development.

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a