;; 
;;=====================================================================================----- 
;; 
;;FUNCTION       CopyFiles2() 
;; 
;;ACTION         Recursively copy files from a source to destination, 
;;               creating subfolders as needed 
;; 
;;AUTHOR         Glenn Barnas 
;; 
;;VERSION        1.0  - 2007/01/31 
;; 
;;HISTORY        1.0  - 2007/01/31 - Initial Release 
;; 
;;SYNTAX         CopyFiles2(Src, Dst [, MD] [, Rec]) 
;; 
;;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 
;; 
;;REMARKS        Same as CopyFiles but with no output 
;; 
;;RETURNS        Nothing 
;; 
;;DEPENDENCIES   DirList() - UDF to recursively scan folders 
;; 
;;TESTED WITH    W2K, WXP, W2K3 
;; 
;;EXAMPLES       None 
; 
Function CopyFiles2($_Src, $_Dst, OPTIONAL $_MD, OPTIONAL $_Recursive)
 
  Dim $_Files, $_File, $_Ec
 
  $CopyFiles2 = 0
 
  $_Recursive = Not Val($_Recursive)	; set recursion on/off (default is ON) 
 
  ; make the base directory if defined and not present 
  If $_MD
    If Not Exist($_Dst)
      MD $_Dst
      $_Ec = @ERROR
      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
      Exit 5
    EndIf
 
    For Each $_File in $_Files
      If GetFileAttr($_Src + '\' + $_File) & 16	; directory - create it 
        MD $_Dst + '\' + Left($_File, Len($_File) - 1)
        $_Ec = IIf(@ERROR = 183, 0, @ERROR)
      Else
        Copy $_Src + '\' + $_File $_Dst + '\' + $_File
        $_Ec = @ERROR
      EndIf
    Next
 
  Else
    Copy $_Src $_Dst
    $_Ec = @ERROR
  EndIf
 
  $CopyFiles2 = Not $_Ec
  Exit $_Ec
 
EndFunction