;; 
;;=====================================================================================----- 
;; 
;;FUNCTION       RepCheck() 
;; 
;;ACTION         Determines if a folder replication is needed 
;; 
;;AUTHOR         Glenn Barnas 
;; 
;;VERSION        1.0  - 2008/01/22 
;; 
;;HISTORY        1.0  - 2008/01/22 - Initial Release 
;; 
;;SYNTAX         RepCheck(Root, RefFile [, Exclusions] [,FullScan]) 
;; 
;;PARAMETERS     Root - REQUIRED - String 
;;               - Root folder of path to scan 
;; 
;;		 RefFile - REQUIRED - String 
;;               - File whose timestamp should be used as a reference 
;; 
;;		 Exclusions - OPTIONAL - Array 
;;               - Array of files/folders to exclude 
;; 
;;		 FullScan - OPTIONAL - Integer 
;;               - A boolean indicating whether a folder or full file scan should be done 
;; 
;;REMARKS        Used to determine if a folder replication should be performed. It 
;;		 compares the timestamp of folders (and files) in a path with the 
;;		 timestamp of a known file. It returns a boolean (0/1), followed by 
;;               a comma-delimited list of files/folders that have changed. 
;; 
;;		 BE SURE TO UPDATE THE RefFile's TIMESTAMP AFTER A REPLICATION!!! 
;;		 An INI file works well for this, writing the current date/time after 
;;               the replication is done. 
;; 
;;RETURNS        String in the format BOOL,list of changed files/folders 
;; 
;;DEPENDENCIES   DirList UDF 
;; 
;;TESTED WITH    W2K, WXP, W2K3 
;; 
;;EXAMPLES       $Rc = RepCheck('e:\data\images', 'e:\data\images\ref.ini', '', 1) 
;;		 If Left($Rc, 1) = 1 
;;		   ; update the ref.ini file and invoke a replication 
;;		 EndIf 
; 
Function RepCheck($_Root, $_Reference, OPTIONAL $_Exclude, OPTIONAL $_FullScan)
 
  Dim $_						; iteration var 
  Dim $_Files, $_File					; Directory enumeration vars 
  Dim $_Last						; last update time 
  Dim $_Time						; folder mod time 
  Dim $_Status						; "must update" status 
  Dim $_Changed						; List of changed folders 
  Dim $_D						; delimiter char 
  Dim $_DirFlag						; true if a directory 
  Dim $_ExFlag						; Exclusion flag 
 
  ; Get the timestamp from the reference file 
  $_Last = TimeConvert(GetFileTime($_Reference))
 
  $_Status = 0
 
  ; Get a list of ALL folders in SWDIST Root - check for modifications newer than the last update 
  ; (compare with \swdist.txt timestamp) and update if modifications are found 
  $_Files = DirList($_Root, 7)				; get list of every file/folder 
  For Each $_File in $_Files
    $_DirFlag = 0
    If Right($_File, 1) = '\' 				; check directories 
      $_DirFlag = 1
      $_File = Left($_File, Len($_File) - 1)		; trim the trailing slash 
    EndIf
 
    If ($_DirFlag And Not $_FullScan) Or $_FullScan
      ; skip certain folders, including Local & deployment 
      $_ExFlag = 0
      For Each $_ in $_Exclude
        If InStr($_File, $_) $_ExFlag = 1 EndIF
      Next      
      If Not $_ExFlag
        $_Time = TimeConvert(GetFileTime($_File))	; get folder mod time in cTime format  
        If $_Time - $_Last > 0
          $_Status = 1
          $_Changed = $_Changed + $_D + $_File
          $_D = ','
        EndIf
      EndIf
 
    EndIf
  Next
 
  $RepCheck = CStr($_Status) + ',' + $_Changed
 
EndFunction