Drive Names and Contents:
This code of segment is for getting DrivesNames and asks user to enter DriveName to view its Contents/Folders.
Code
using System.IO;
public class DrivesInfo
{
public static void Main(string[] args)
{
foreach (DriveInfo dinfo in DriveInfo.GetDrives())
//To skip those drives which don't have folders like floppyDisk
if (dinfo.IsReady)
{
Console.WriteLine(dinfo.Name, dinfo.DriveType);
}
Console.WriteLine("Enter Letter Of Drive To Browse Its Contents");
//Asking user to enter drive letter
ConsoleKeyInfo getKey = Console.ReadKey(true);
DirectoryInfo info = new DirectoryInfo(getKey.Key.ToString() + @":\");
//Showing folder names of user input drive letter
foreach (DirectoryInfo d in info.GetDirectories())
Console.WriteLine(d.Name);
Console.ReadLine();
}
}
0 comments:
Post a Comment