Aqui os dejo una función util, encargada de copiar todo un directorio
en la ruta especificada.
Private Shared Sub DirectoryCopy( _
ByVal sourceDirName As String, _
ByVal destDirName As String, _
ByVal copySubDirs As Boolean)
Dim dir As System.IO.DirectoryInfo = New System.IO.DirectoryInfo(sourceDirName)
Dim dirs As System.IO.DirectoryInfo() = dir.GetDirectories()
' If the source directory does not exist, throw an exception.
If Not dir.Exists Then
Throw New System.IO.DirectoryNotFoundException( _
"Source directory does not exist or could not be found: " _
+ sourceDirName)
End If
' If the destination directory does not exist, create it.
If Not System.IO.Directory.Exists(destDirName) Then
System.IO.Directory.CreateDirectory(destDirName)
End If
' Get the file contents of the directory to copy.
Dim files As System.IO.FileInfo() = dir.GetFiles()
Dim file As System.IO.FileInfo
For Each file In files
' Create the path to the new copy of the file.
Dim temppath As String = Path.Combine(destDirName, file.Name)
' Copy the file.
file.CopyTo(temppath, False)
Next file
' If copySubDirs is true, copy the subdirectories.
If copySubDirs Then
For Each dir In dirs
' Create the subdirectory.
Dim temppath As String = _
Path.Combine(destDirName, dir.Name)
' Copy the subdirectories.
DirectoryCopy(dir.FullName, temppath, copySubDirs)
Next dir
End If
End Sub
Saludos
Carlos Javier Martín Cano
No hay comentarios:
Publicar un comentario