Advertisement
7_2009-2012 Files/ File Controls/ Input/ Output #234300

Sync Folders from Server

This will copy folders from one location to another continuously checking if there are new folders created on the server and checking the last date accessed for the server location to copy to the local computer or other location. This is setup for no user input and will run until it is killed by the Task Manager.

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
Dim fso
  Dim n As Double 'Use n for the array variable
  Dim TIFolders(100000) As String 'Create an array for the original folders
  Dim AgentFolders(100000) As String 'Create an array for the destination folders
  Dim TIDate 'Designated for the GetFolder command for the original folders
  Dim AgentDate 'Designated for the GetFolder command for the destination folders
  
  Do While Now() = Now()                         'Set to continuously run until you kill it in Task Manager
    Set fso = CreateObject("Scripting.FileSystemObject") 'Set up to access FileSystemObject properties
    For n = 0 To 99999                           'n can be set to any amount within the arrays
      TIFolders(n) = "\\<SERVER FOLDER LOCATION>\" & n 'Set the location of the original folder
      AgentFolders(n) = "\\<LOCAL OR OTHER SERVER LOCATION>\" 'Set the destination location of the copy
      
      If fso.FolderExists(TIFolders(n)) Then 'Checking if the folder exists in the original location
        If fso.FolderExists(AgentFolders(n) & n) Then 'Checking to see if the folder exists on the destination location
          Set TIDate = fso.GetFolder(TIFolders(n)) 'Gets the folder information from the original location
          Set AgentDate = fso.GetFolder(AgentFolders(n)) 'Gets the folder information from the destination location
          If TIDate.DateLastAccessed < AgentDate.DateLastAccessed Then 'If the original location was accessed before
                                                              'the destination location,Then nothing...
          Else
            fso.DeleteFolder AgentFolders(n) & n, True 'Delete destination location
            fso.CopyFolder TIFolders(n), AgentFolders(n) & "\" 'Copy original location to the destination location
          End If
        Else
          fso.CopyFolder TIFolders(n), AgentFolders(n) & "\" 'Otherwise, just copy the original location to the destination location
        End If
      End If
      
    Next n 'Go to the next folder in the array
    
    Set fso = Nothing 'Destroy to free memory
    Set TIDate = Nothing 'Destroy to free memory
    Set AgentDate = Nothing 'Destroy to free memory
  Loop 'Start the whole process again...
Original Comments (3)
Recovered from Wayback Machine