亲宝软件园·资讯

展开

拷贝整个目录下所有子目录及文件 VB.NET拷贝整个目录下所有子目录及文件的实例代码

人气:0
想了解VB.NET拷贝整个目录下所有子目录及文件的实例代码的相关内容吗,在本文为您仔细讲解拷贝整个目录下所有子目录及文件的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点: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

加载全部内容

相关教程
猜你喜欢
用户评论