tags:

views:

108

answers:

1

I want to get the name or label of drive.

I use this function :

function GetVolumeLabel(DriveChar: Char): string;
var
  NotUsed:     DWORD;
  VolumeFlags: DWORD;
  VolumeInfo:  array[0..MAX_PATH] of Char;
  VolumeSerialNumber: DWORD;
  Buf: array [0..MAX_PATH] of Char;
begin
    GetVolumeInformation(PChar(DriveChar + ':\'),
    Buf, SizeOf(VolumeInfo), @VolumeSerialNumber, NotUsed,
    VolumeFlags, nil, 0);

    SetString(Result, Buf, StrLen(Buf));   { Set return result }
    Result:=AnsiUpperCase(Result)
end;

For example, here're my drives in Windows Explorer :

Local Disk (C:)
Data (D:)
DVD RW Drive (E:)

The output of the code :

C: 
D: DATA
E:

The labels of C and E are empty. What winapi/function should I use to display the label of unnamed drive (C and E)?

+1  A: 

I believe that "Local Disk" and "DVD RW Drive" are used for placeholders when there's no volume labels. From MSDN:

A label is a user-friendly name that is assigned to a volume, usually by an end user, to make it easier to recognize. A volume can have a label, a drive letter, both, or neither.

Not sure if this helps, but you might want to use GetDriveType and generate the labels based on the return Value. While GetDriveType differentiates between hard drives, removable drives and CD type drives, I don't think it does not separate between CD-ROM/CD-RW/DVD-ROM/DVD-RW drives.

Mr Roys