手上的东西需要一个目录复制,不过好久没有写程序,只好将就着将它写出来。
目录复制无非是取文件,递归代码如下:
Public Sub CopyDirectory(ByVal sourceDirName As String, ByVal destDirName As String)
If Not (Microsoft.VisualBasic.Right(destDirName, 1) = Path.DirectorySeparatorChar) Then
''取目标数程序,最后一个字符是否是“/”,不是则加上
destDirName = destDirName + Path.DirectorySeparatorChar
End If
Try
Dim files As String() = Directory.GetFiles(sourceDirName)
For Each strfile As String In files
File.Copy(strfile, destDirName + Path.GetFileName(strfile), True) '复制文件
File.SetAttributes(destDirName + Path.GetFileName(strfile), FileAttributes.Normal)
Next
Dim dirs As String() = Directory.GetDirectories(sourceDirName)
Dim targDir As String
For Each mydir As String In dirs
targDir = destDirName + StrCat(mydir, sourceDirName)
Directory.CreateDirectory(targDir) '''建立此目录
CopyDirectory(mydir, targDir)''递归遍历
Next
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Sub