vb.net – VB 2010:如何复制其他文件夹中文件夹的所有子文件夹
发布时间:2020-12-17 00:02:32 所属栏目:大数据 来源:网络整理
导读:我在Visual Basic 2010中遇到了一个问题:如何将所有子文件夹(仅子文件夹,而不是主文件夹)复制到另一个文件夹中? 谢谢您的帮助! 您需要通过所有文件和文件夹recursivly iterat并复制它们.这种方法可以帮到你: Public Sub CopyDirectory(ByVal sourcePath
我在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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |