萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> asp.net編程 >> VB.NET拷貝整個目錄下所有子目錄及文件的實例代碼

VB.NET拷貝整個目錄下所有子目錄及文件的實例代碼

這篇文章介紹了拷貝整個目錄下所有子目錄及文件的代碼,有需要的朋友可以參考一下   復制代碼 代碼如下:


 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()
       // 遞歸調用自身
        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 SettingsusernameFavorites"), New DirectoryInfo("g: emp"))
    End Sub

copyright © 萬盛學電腦網 all rights reserved