Home »
.Net »
C# Programs
C# program to demonstrate the use of CreateSubdirectory method
In this article, we will learn how to create a sub-directory? Here we will use class DirectoryInfo to create sub-directory using method CreateSubdirectory.
Submitted by IncludeHelp, on November 16, 2017
DirectoryInfo.CreateSubdirectory()
This is a method of "DirectoryInfo" class, it is used to create a sub directory within a directory.
Syntax:
DirectoryInfo DirectoryInfo.CreateSubdirectory(string path);
Parameter(s):
- path - Sub-Directory name.
Return value:
Returns the object of DirectoryInfo class.
Program
using System;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main()
{
DirectoryInfo d = new DirectoryInfo("mydir");
d.CreateSubdirectory("sub-dir");
Console.WriteLine("Sub-Directory created successfully");
}
}
}
Output
Sub-Directory created successfully.
In this program we create an object of DirectoryInfo class and initialize with a directory-name, then create sub-directory inside given directory.
Note: In above program, we need to remember, when we use "DirectoryInfo" class, System.IO namespace must be included in the program.
C#.Net DirectoryInfo Class Programs »