Create Nested Directories in C# and VB.NET

A lot of developers do not know that Directory.CreateDirectory() can be used to create directories and subdirectories as specified by the path. Here’s an example

C#

static void Main(string[] args)
{
try
{
Directory.CreateDirectory(@"D:\ParentDir\ChildDir\SubChildDir\");
Console.WriteLine("Directories Created");
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}

VB.NET

Shared Sub Main(ByVal args() As String)
Try
Directory.CreateDirectory("D:\ParentDir\ChildDir\SubChildDir\")
Console.WriteLine("Directories Created")
Console.ReadLine()
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Sub

OUTPUT

CreateNestedDirectories

2 comments:

  1. The .NET framework comes bundled with a lot of advantages, which makes it widely used tool for .NET application development. In .NET ,
    I need some explanation regarding c# to vb conversion..
    Anykind of help would be greatly appreciated.

    ReplyDelete
  2. Your article is very interesting. It is very useful and helpful for the Developers to develop the application. Thanks for share this valuable post.

    ReplyDelete