ディレクトリコピー
Private Sub CopyDirectory(ByVal sourceDirName As String, ByVal destDirName As String)
'コピー先のディレクトリがないときは作る
If Not Directory.Exists(destDirName) Then
Directory.CreateDirectory(destDirName)
'属性もコピー
File.SetAttributes(destDirName, _
File.GetAttributes(sourceDirName))
End If
'コピー先のディレクトリ名の末尾に"\"をつける
If destDirName.Chars((destDirName.Length - 1)) <> _
Path.DirectorySeparatorChar Then
destDirName = destDirName + Path.DirectorySeparatorChar
End If
'コピー元のディレクトリにあるファイルをコピー
Dim fs As String() = Directory.GetFiles(sourceDirName)
Dim f As String
For Each f In fs
File.Copy(f, _
destDirName + Path.GetFileName(f), True)
Next
'コピー元のディレクトリにあるディレクトリをコピー
Dim dirs As String() = Directory.GetDirectories(sourceDirName)
Dim dir As String
For Each dir In dirs
CopyDirectory(dir, destDirName + Path.GetFileName(dir))
Next
End Sub