VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Copy a dir to another directory including the sub directories.

by emilemily (1 Submission)
Category: Files/File Controls/Input/Output
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Fri 22nd September 2000
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Copy a dir to another directory including the sub directories.

Rate Copy a dir to another directory including the sub directories.



    ReDim FileName(1) As String
    
    'check the directory string
    If Right(FromPath, 1) <> "\" Then FromPath = FromPath & "\"
    If Right(ToPath, 1) <> "\" Then ToPath = ToPath & "\"
    
    'real direcotry
    If (Dir(FromPath, vbDirectory) <> "") And (Dir(ToPath, vbDirectory) <> "") Then
        Dim i As Integer
        i = 0
        FileName(i) = Dir(FromPath, vbDirectory)
        While FileName(i) <> ""
            If (GetAttr(FromPath & FileName(i)) And vbDirectory) = vbDirectory Then
                If FileName(i) <> "." And FileName(i) <> ".." Then
                    i = i + 1
                    ReDim Preserve FileName(i + 1) As String
                End If
            Else
                FileCopy FromPath & FileName(i), ToPath & FileName(i)
            End If
            'increase the array size
            FileName(i) = Dir
        Wend
        
        'copy the sub directory
        If i > 0 Then
            For Each directory In FileName
                If directory <> "" Then
                    'prepare directory
                    MkDir ToPath & directory
                    
                    'copy direcotry
                    dirCopy FromPath & directory, ToPath & directory
                End If
            Next
        End If
    End If
End Sub

Download this snippet    Add to My Saved Code

Copy a dir to another directory including the sub directories. Comments

No comments have been posted about Copy a dir to another directory including the sub directories.. Why not be the first to post a comment about Copy a dir to another directory including the sub directories..

Post your comment

Subject:
Message:
0/1000 characters