Examples Delphi

The following code enumerates the drives on the local computer using the Windows API GetDriveType. This function was introduced with Windows 95 already, so there is no need to use the other code posted on this site (which was written for Windows 3.1 and worked until Windows 98).

procedure TForm1.Button1Click(Sender: TObject);
var
i,
iType: integer;
s: String;
begin { TForm1.Button1Click }
for i := 0 to 25 do
begin
s := Chr(i + 65) + ':';
iType := GetDriveType(PChar(s));
case iType of
DRIVE_REMOVABLE:
ListBox1.Items.Add(Chr(i + 65) + ': floppy');
DRIVE_FIXED:
ListBox1.Items.Add(Chr(i + 65) + ': hard disk');
DRIVE_CDROM:
ListBox1.Items.Add(Chr(i + 65) + ': CDROM');
DRIVE_RAMDISK:
ListBox1.Items.Add(Chr(i + 65) + ': RAMDisk');
DRIVE_REMOTE:
ListBox1.Items.Add(Chr(i + 65) + ': network drive');
end; { case iType }
end; { for i }
end; { TForm1.Button1Click }