熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

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

2013-11-13 10:36:34  來源: .NET編程 
這篇文章介紹了拷貝整個目錄下所有子目錄及文件的代碼有需要的朋友可以參考一下   復制代碼 代碼如下:

  
 Public Sub CopyDerictory(ByVal DirectorySrc As DirectoryInfo ByVal DirectoryDes As DirectoryInfo)
        Dim strDirectoryDesPath As String = DirectoryDesFullName & "" & DirectorySrcName
        If Not DirectoryExists(strDirectoryDesPath) Then
            DirectoryCreateDirectory(strDirectoryDesPath)
        End If
        Dim f fs() As FileInfo
        fs = DirectorySrcGetFiles()
        For Each f In fs
            FileCopy(fFullName strDirectoryDesPath & "" & fName True)
        Next
        Dim DirSrc Dirs() As DirectoryInfo
        Dirs = DirectorySrcGetDirectories()
       // 遞歸調用自身
        For Each DirSrc In Dirs
            Dim DirDes As New DirectoryInfo(strDirectoryDesPath)
            CopyDerictory(DirSrc DirDes)
        Next
    End Sub
    Private Sub Button_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles ButtonClick
        CopyDerictory(New DirectoryInfo("C:Documents and SettingsusernameFavorites") New DirectoryInfo("g: emp"))
    End Sub


From:http://tw.wingwit.com/Article/program/net/201311/14105.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.