微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

vb.net – VB 2010:如何复制其他文件夹中文件夹的所有子文件夹?

我在Visual Basic 2010中遇到了一个问题:如何将所有子文件夹(仅子文件夹,而不是主文件夹)复制到另一个文件夹中?

谢谢您的帮助!

您需要通过所有文件文件夹recursivly iterat并复制它们.这种方法可以帮到你:
Public Sub copyDirectory(ByVal sourcePath As String,ByVal destinationPath As String)
    Dim sourceDirectoryInfo As New System.IO.DirectoryInfo(sourcePath)

    ' If the destination folder don't exist then create it
    If Not System.IO.Directory.Exists(destinationPath) Then
        System.IO.Directory.CreateDirectory(destinationPath)
    End If

    Dim fileSystemInfo As System.IO.FileSystemInfo
    For Each fileSystemInfo In sourceDirectoryInfo.GetFileSystemInfos
        Dim destinationFileName As String =
            System.IO.Path.Combine(destinationPath,fileSystemInfo.Name)

        ' Now check whether its a file or a folder and take action accordingly
        If TypeOf fileSystemInfo Is System.IO.FileInfo Then
            System.IO.File.copy(fileSystemInfo.FullName,destinationFileName,True)
        Else
            ' Recursively call the mothod to copy all the neste folders
            copyDirectory(fileSystemInfo.FullName,destinationFileName)
        End If
    Next
End Sub

原文地址:https://www.jb51.cc/vb/255937.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐