;; 
;;=====================================================================================----- 
;; 
;;FUNCTION       CopyFiles() 
;; 
;;ACTION         Recursively copy files from a source to destination, 
;;               creating subfolders as needed 
;; 
;;AUTHOR         Glenn Barnas 
;; 
;;VERSION        1.1 - 2014/12/27 
;; 
;;HISTORY        1.0 - 2007/01/31 - Initial Release 
;;               1.1 - 2014/12/27 - Replaced Msg()/LMsg() with fMsg() for output 
;; 
;;SYNTAX         CopyFiles(Src, Dst [, MD] [, Rec] [, silent]) 
;; 
;;PARAMETERS     Src - REQUIRED 
;;               - Source folder and file spec (*.*) 
;; 
;;               Dst - REQUIRED 
;;               - Destination path 
;; 
;;               MD - OPTIONAL 
;;               - Flag permitting creation of the dest root 
;; 
;;               Rec - OPTIONAL 
;;               - Flag enabling recursive copies 
;; 
;;		 Silent- OPTIONAL 
;;               - Run without messages 
;; 
;;REMARKS         
;; 
;;RETURNS        Nothing 
;; 
;;DEPENDENCIES   fMsg(), DirList() - UDFs 
;; 
;;TESTED WITH    W2K, WXP, W2K3 
;; 
;;EXAMPLES       None 
; 
Function CopyFiles($_Src, $_Dst, $_MD, $_Recursive, OPTIONAL $_Silent)
 
  Dim $_Error, $_Files, $_File, $_Ec, $_Es
 
  If $_Silent $_Silent = 16 EndIf		; set log-only mode in fMsg() 
 
  $_Error = 'The commands completed successfully.'
 
  ; make the base directory if defined and not present 
  If $_MD
    If Not Exist($_Dst)
      fMsg(' MD ' + $_Dst, '', 0, $_Silent)
      If Not $DEBUG
        MD $_Dst
        $_Ec = @ERROR $_Es = @SERROR
      EndIf	; debug 
      If $_Silent Msg('   - ' + $_Es) Else LMsg('   - ' + $_Es) EndIf
      If $_Ec = 5
        Exit 5				; exit on access denied! 
      EndIf	; error 
    EndIf	; not exist 
  EndIf		; MD? 
 
  ; handle recursive copies, making subfolders as needed 
  If $_Recursive
 
    $_Files = DirList($_Src, 5)
    If @ERROR = 5
      fMsg(' Access is denied reading the source folder!', '', 0, $_Silent)
      Exit 5
    EndIf
 
    For Each $_File in $_Files
      If GetFileAttr($_Src + '\' + $_File) & 16	; directory - create it 
        If Not $DEBUG
          $_Es = ''
          MD $_Dst + '\' + Left($_File, Len($_File) - 1)
          $_Ec = IIf(@ERROR = 183, 0, @ERROR)
          $_Ec = @ERROR
          If $_Ec $_Error = 'At least one copy operation failed.' $_Es = @CRLF + '   - ' + @SERROR EndIf
        Else
          $_Es = 'The command completed successfully.'
        EndIf
        fMsg(' MD ' + $_Dst + '\' + $_File + $_Es, '', 0, $_Silent)
      Else
        If Not $DEBUG
          $_Es = ''
          Copy $_Src + '\' + $_File $_Dst + '\' + $_File
          $_Ec = @ERROR
          If $_Ec $_Error = 'At least one copy operation failed.'  $_Es = @CRLF + '   - ' + @SERROR EndIf
        EndIf
        fMsg(' copy ' + $_Src + '\' + $_File + @CRLF + '   -> ' + $_Dst + '\' + $_File + $_Es, '', 0, $_Silent)
      EndIf
    Next
 
    fMsg(' copy ' + $_Src + @CRLF + '  -> '  + $_Dst + '\' + $_File + @CRLF + '   - ' + $_Error, '', 0, $_Silent)
  Else
    If Not $DEBUG
      Copy $_Src $_Dst
    EndIf
    fMsg(' copy ' + $_Src + @CRLF + '  -> '  + $_Dst + '\' + $_File + @CRLF + '   - ' + @SERROR, '', 0, $_Silent)
  EndIf
 
 
EndFunction