Tips: FreeBasic: CopyFolder


#Include once "dir.bi"
#Include once "file.bi"
#Include Once "string.bi"
#include once "ext/strings/strsplit.bi"
#Include Once "win/shlobj.bi"

sub copyfolder(dirName as string, dstdir as string)
    const attrib_mask = fbDirectory  or fbNormal Or fbHidden Or fbSystem or fbReadOnly or fbArchive
    dim as uinteger out_attr
    dim fileName as string
    dim absname as String
    
    fileName = Dir(dirName + "\*", attrib_mask, out_attr)
    print "fileName >>>> " + fileName
    Do Until Len(fileName) = 0 '' loop until Dir returns empty string
        If (fileName <> ".") And (fileName <> "..") Then '' ignore current and parent directory entries
     
            absName = dirName & "\" & fileName
            '
            If out_attr And fbDirectory Then
                dim d as string
                d = right(absName,Len(absName) - InStrRev(absName, "\"))
                Print "d = " + d        
                Print "absName =" + absName                
                dstDir = dstDir + "\" + d 
                Print "DST = " + dstdir
                
                SHCreateDirectoryEx(0,StrPtr(dstDir),0)
                copyfolder(absName, dstDir )
            Else
                dim d as String
                d = right(absName,Len(absName) - InStrRev(absName, "\"))
                SHCreateDirectoryEx(0,StrPtr(dstDir),0)
                FileCopy(absName, dstdir + "\" + d)
                Print "file: " + absName + " DST: " + dstDir
            End If
        End If
      fileName = Dir(out_attr)
    Loop
end sub