Show list of valid drives

Posted in Files & folders

Use GetLogicalDriveStrings function for solving of this problem. This function returns point to a string, which has such representing: c:\#0d:\#0#0.

procedure TForm1.Button1Click(Sender: TObject);
var
  MyStr: PChar;
  i, Length: Integer;
const
  Size: Integer = 200;
begin
  GetMem(MyStr, Size);
  Length:=GetLogicalDriveStrings(Size, MyStr);
  for i:=0 to Length-1 do
  begin
    if (MyStr[i]>='a')and(MyStr[i]<='z') then
      Memo1.Lines.Add(MyStr[i]+':\');
  end;
  FreeMem(MyStr);
end;