Drive
In this chapter you will learn:
List all drives
using System;//j a va 2s.co m
using System.IO;
static class MainClass
{
static void Main(string[] args)
{
foreach (DriveInfo drive in DriveInfo.GetDrives())
{
try
{
Console.WriteLine(
"{0} - {1} KB",
drive.RootDirectory,
drive.AvailableFreeSpace / 1024
);
} catch (IOException) {
Console.WriteLine(drive);
}
}
}
}
The code above generates the following result.
Get all logical drives
using System;/*ja v a2 s. c om*/
using System.IO;
class MaionClass
{
public static void Main(String[] args)
{
string[] drives = Directory.GetLogicalDrives();
Console.WriteLine("Here are your drives:");
foreach(string s in drives)
{
Console.WriteLine("--> {0}", s);
}
}
}
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
Home » C# Tutorial » File, Path