Get Drive Name in CSharp
Description
The following code shows how to get Drive Name.
Example
using System;/*from www. j av a2 s. c om*/
using System.IO;
class MainClass {
static void Main(string[] args) {
FileInfo file = new FileInfo("c:\\a.txt");
// Display drive information.
DriveInfo drv = new DriveInfo(file.FullName);
Console.Write("Drive: ");
Console.WriteLine(drv.Name);
}
}
The code above generates the following result.