Open In App

C# Program to Demonstrate the Use of CreateSubdirectory Method

DirectoryInfo class provides different types of methods and properties that are used to perform operations on directories and sub-directories like creating, moving, etc. This class has a CreateSubdirectory() method that is used to create a sub-directory or sub-directories on the given path. Here the given path can be relative to this instance of the DirectoryInfo class.

Syntax:



public System.IO.DirectoryInfo CreateSubdirectory (string spath);

Here, the spath parameter represents the specified path.



Return: It will return the last directory that is specified in the path.

Exceptions:

Example:




// C# program demonstrate the working
// of CreateSubdirectory() method
using System;
using System.IO;
  
class GFG {
  
    static void Main()
    {
  
        // Getting the vignan directory
        DirectoryInfo my_dir = new DirectoryInfo("vignan");
  
        // Creating sub directory named IT
        // in the vignan directory
        // using CreateSubdirectory() method
        my_dir.CreateSubdirectory("IT");
  
        Console.WriteLine("IT  created successfully");
    }
}

Output:

IT  created successfully
Article Tags :