Copiare cartelle ricorsivamente in Vb.Net

 Vi posto la versione Vb.Net di questa funzione che ho trovato davvero molto utile:

Public Shared Sub copyDirectory(ByVal Src As StringByVal Dst As String)
        
Dim Files() As [String]

        
If Dst.Chars(Dst.Length - 1) <> Path.DirectorySeparatorChar Then
            
Dst += Path.DirectorySeparatorChar
        
End If

        If Not Directory
.Exists(Dst) Then
            Directory
.CreateDirectory(Dst)
        
End If

        
Files = Directory.GetFileSystemEntries(Src)
        
Dim Element As String

        For Each 
Element In Files
            
' Sub directories
            
If Directory.Exists(Element) Then
                
copyDirectory(Element, Dst + Path.GetFileName(Element))
                
' Files in directory
            
Else
                
File.Copy(Element, Dst + Path.GetFileName(Element), True)
            
End If
        Next 
Element
End Sub

Print | posted on mercoledì 12 gennaio 2005 18:11