How to display an unnamed drive label?

I want to get a name or drive label.

I am using 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 are my drives in Windows Explorer:

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

Code output:

C: 
D: DATA
E:

Labels C and E are empty. What winapi / function should be used to display an unnamed drive label (C and E)?

+3
source share
1 answer

I believe that “Local Disk” and “DVD RW Drive” are used for placeholders if there are no volume labels. From MSDN :

A shortcut is a convenient name that is assigned to that usually of the end user in order to simplify recognition. A volume can have a label, drive letter, and both.

, , GetDriveType . GetDriveType , CD, , CD-ROM/CD-RW/DVD-ROM/DVD-RW.

+4

Source: https://habr.com/ru/post/1745733/


All Articles