You are assigned to develop a project(complete codes) in which project
manager wants following functionality.
1. Create Student Folder in C drive using Directory class.
CreateFolder();
static void CreateFolder()
{
try
{
DirectoryInfo info;
Console.Write("Specify the path or type 'drive C' to create a Student folder: ");
string? path = Console.ReadLine();
switch (path)
{
case "drive C":
info = Directory.CreateDirectory("C:\\Student");
break;
default:
info = Directory.CreateDirectory(path + "\\Student");
break;
}
Console.WriteLine("");
Console.Write("To exit the program, press Enter.");
Console.ReadLine();
}
catch (DirectoryNotFoundException e)
{
Console.WriteLine("Failed to create folder.");
CreateFolder();
}
}
Comments
Leave a comment