+92 332 4229 857 99ProjectIdeas@Gmail.com

Drive Names and Contents (C#.net)



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: