VOOZH about

URL: https://www.geeksforgeeks.org/c-sharp/c-sharp-program-to-demonstrate-the-use-of-createsubdirectory-method/

⇱ C# Program to Demonstrate the Use of CreateSubdirectory Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

C# Program to Demonstrate the Use of CreateSubdirectory Method

Last Updated : 1 Feb, 2022

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:

  • ArgumentException: This exception will occur when the spath does not specify a valid file path or contains invalid DirectoryInfo characters.
  • ArgumentNullException: This exception will occur when the spath is null.
  • DirectoryNotFoundException: This exception will occur when the specified spath is invalid, such as being on an unmapped drive.
  • IOException: This exception will occur when the subdirectory cannot be created.
  • PathTooLongException: This exception will occur when the specified spath, file name, or both exceed the system-defined maximum length.
  • SecurityException: This exception will occur when the caller does not have code access permission to create the directory.
  • NotSupportedException: This exception will occur when the spath contains a colon character (:) which is not the part of the given drive label (e.g. "E:\").

Example:

Output:

IT created successfully
Comment
Article Tags:
Article Tags:

Explore