...get the volume name?

Author: Rainer K├╝mmerle
Homepage: http://www.thinklazy.de

Category: System

function GetVolumeName(DriveLetter: Char): string;
var
  
dummy: DWORD;
  buffer: array[0..MAX_PATH] of Char;
  oldmode: LongInt;
begin
  
oldmode := SetErrorMode(SEM_FAILCRITICALERRORS);
  try
    
GetVolumeInformation(PChar(DriveLetter + ':\'),
                         buffer,
                         SizeOf(buffer),
                         nil,
                         dummy,
                         dummy,
                         nil,
                         0);
    Result := StrPas(buffer);
  finally
    
SetErrorMode(oldmode);
  end;
end;

// Example, Beispiel:

procedure TForm1.Button1Click(Sender: TObject);
begin
  
Caption := GetVolumeName('c');
end;

 

printed from
www.swissdelphicenter.ch
developers knowledge base