明輝手游網(wǎng)中心:是一個(gè)免費(fèi)提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺(tái)!

拷貝整個(gè)目錄下所有子目錄及文件的方法

[摘要]Public Sub CopyDerictory(ByVal DirectorySrc As DirectoryInfo, ByVal DirectoryDes As DirectoryInfo) Dim strDirectoryDesPath As String = Directo...
 Public Sub CopyDerictory(ByVal DirectorySrc As DirectoryInfo, ByVal DirectoryDes As DirectoryInfo)
        Dim strDirectoryDesPath As String = DirectoryDes.FullName & "\" & DirectorySrc.Name

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

        Dim f, fs() As FileInfo

        fs = DirectorySrc.GetFiles()

        For Each f In fs
            File.Copy(f.FullName, strDirectoryDesPath & "\" & f.Name, True)
        Next

        Dim DirSrc, Dirs() As DirectoryInfo


        Dirs = DirectorySrc.GetDirectories()

        '遞歸調(diào)用自身
        For Each DirSrc In Dirs
            Dim DirDes As New DirectoryInfo(strDirectoryDesPath)
            CopyDerictory(DirSrc, DirDes)
        Next
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        CopyDerictory(New DirectoryInfo("C:\Documents and Settings\username\Favorites"), New DirectoryInfo("g:\temp"))
    End Sub