C# DriveInfo VolumeLabel

Description

DriveInfo VolumeLabel Gets or sets the volume label of a drive.

Syntax

DriveInfo.VolumeLabel has the following syntax.


public string VolumeLabel { get; set; }

Example

Gets the volume label of a drive.


using System;/*from   w  ww.  j  a  va2  s.  c om*/
using System.IO;

class Test
{
    public static void Main()
    {
        DriveInfo[] allDrives = DriveInfo.GetDrives();

        foreach (DriveInfo d in allDrives)
        {
            Console.WriteLine("Drive {0}", d.Name);
            Console.WriteLine("  File type: {0}", d.DriveType);
            if (d.IsReady == true)
            {
                Console.WriteLine("  Volume label: {0}", d.VolumeLabel);
                Console.WriteLine("  File system: {0}", d.DriveFormat);
                Console.WriteLine(d.AvailableFreeSpace);

                Console.WriteLine(d.TotalFreeSpace);

                Console.WriteLine(d.TotalSize);
            }
        }
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.IO »




BinaryReader
BinaryWriter
Directory
DirectoryInfo
DriveInfo
File
FileInfo
FileStream
MemoryStream
Path
StreamReader
StreamWriter
StringReader
StringWriter