Drive Information C# with Example



Drive Information C# with Example

 using System.IO;
using System;

namespace CSharpFilesAndStreams
{
	class Program
	{
		static void Main(string[] args)
		{
			// Get info regarding all drives.
			DriveInfo[] myDrives = DriveInfo.GetDrives();

			// Now print drive stats.
			foreach(DriveInfo d in myDrives)
			{
				Console.WriteLine("Name: {0}", d.Name);
				Console.WriteLine("Type: {0}", d.DriveType);

				// Check to see whether the drive is mounted.
				if(d.IsReady)
				{
					Console.WriteLine("Free space: {0}", d.TotalFreeSpace);
					Console.WriteLine("Format: {0}", d.DriveFormat);
					Console.WriteLine("Label: {0}", d.VolumeLabel);
				}
				Console.WriteLine();
			}
			Console.ReadLine();
		}
	}
}	 

0 Comment's

Comment Form

Submit Comment