Link to home
Start Free TrialLog in
Avatar of eNarc
eNarcFlag for United Kingdom of Great Britain and Northern Ireland

asked on

how to get the list of active hard drives

Hi, how do I get the list of active Hard Drives that are connected?

and list them in a combobox drop down as C: H: etc
ASKER CERTIFIED SOLUTION
Avatar of barlet
barlet
Flag of North Macedonia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
rename Memo1.Lines.Add to ComboBox1.Items.Add

and you will have them all in Combobox :)
Try this
var
  Drive : byte;
  DriveName: string;
  mybutton: TsBitBtn;
begin
  ComboBox1.Items.Clear;
  for Drive := 0 to 25 do
    If DriveExists(Drive) then
    begin
      DriveName := Chr(Drive + $41) + ':';
      case GetDriveType(PChar(DriveName)) of
        DRIVE_UNKNOWN: ComboBox1.Items.Add(DriveName + ' Unknown');// The drive type cannot be determined.
        DRIVE_NO_ROOT_DIR: ComboBox1.Items.Add(DriveName + ' No root dir');// The root path is invalid; for example, there is no volume is mounted at the path.
        DRIVE_REMOVABLE: ComboBox1.Items.Add(DriveName + ' Removable');// The drive has removable media; for example, a floppy drive or flash card reader.
        DRIVE_FIXED: ComboBox1.Items.Add(DriveName + ' Fixed');// The drive has fixed media; for example, a hard drive, flash drive, or thumb drive.
        DRIVE_REMOTE: ComboBox1.Items.Add(DriveName + ' Remote');// The drive is a remote (network) drive.
        DRIVE_CDROM: ComboBox1.Items.Add(DriveName + ' CDRom');// The drive is a CD-ROM drive.
        DRIVE_RAMDISK: ComboBox1.Items.Add(DriveName + ' Ram');// The drive is a RAM disk.
      end;
    end;

Open in new window

This is the link where barlet's code is from... ;o))

[DELPHI] - Get Drives And Types
http://www.vbforums.com/showthread.php?t=346506
hehe same code but not from there :)

I think i got it from here
sorry wrong link this is the correct http://delphi.about.com/cs/adptips1999/a/bltip0599_5.htm :)
Avatar of Ephraim Wangoya
Just make it simple
procedure TForm1.LoadDrives;
var
  C: Char;
  Drive : String;
begin
  for C := 'A' To 'Z' Do
  begin
    Drive := C + ':\';
    if GetDriveType(PChar(Drive)) = DRIVE_FIXED  then
      ComboBox1.Items.Add(C + ':');
  end;
end;

Open in new window