Saturday, 26 January 2013

Create a Directory Structure VB.NET

Create a Directory Structure VB.NET

Creating a Empty Directory Structure using Vb.NET, Directories and Sub directories with in specified source directory,

Shared  Sub CreateDirectoryStructure(ByVal szDir As String, ByVal destDir As String)

'for C drive root path is C:\

'for D drive root path is D:\
'Replace Source path root with destination path root.

Dim destpathroot As String =  Path.GetPathRoot(destDir)

Dim srcpathroot As String =  Path.GetPathRoot(szDir)
Dim dirs() As String =  Directory.GetDirectories(szDir,"*",SearchOption.AllDirectories)
Dim difVolume As String
For Each difVolume In dirs

Dim path As String =  difVolume.Replace(srcpathroot,destpathroot)
If Not Directory.Exists(path) Then
End If

Catch ex As Exception
End Try
End Sub
for ex:

Public Shared  Sub Main()

'Creates a Empty Directory Structure of Inetpub located in C drive in D:\
End Sub

Tags:Create a Directory Structure VB.NET,Replicate folder Structure,Create Directory Structure,Folder Recursion,System.IO.Directory,System.IO.DirectoryInfo,Replicates directory Structure VB.NET