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

到此这篇关于VB.NET拷贝整个目录下所有子目录及文件的实例代码就介绍到这了。学的时候就要想着现在和将来怎么去用,否则是浪费时间。更多相关VB.NET拷贝整个目录下所有子目录及文件的实例代码内容请查看相关栏目,小编编辑不易,再次感谢大家的支持!

标签: VB