gpt4 book ai didi

vb.net - VB 2010 : How to copy all subfolders of a folder in an other folder?

转载 作者:行者123 更新时间:2023-12-03 18:23:59 26 4
gpt4 key购买 nike

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

谢谢您的帮助!

最佳答案

您需要递归遍历所有文件和文件夹并复制它们。这种方法应该为您完成这项工作:

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

关于vb.net - VB 2010 : How to copy all subfolders of a folder in an other folder?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5525573/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com