how to get the list of active hard drives

eNarc
eNarc used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
try this

procedure TForm1.Button1Click(Sender: TObject);
var
  Drive: Char;
  DriveLetter: String[4];
begin
  for Drive := 'A' to 'Z' do
  begin
   DriveLetter := Drive + ':\';
   case GetDriveType(PChar(Drive + ':\')) of
    DRIVE_REMOVABLE:
     Memo1.Lines.Add(DriveLetter + ' Floppy Drive') ;
    DRIVE_FIXED:
     Memo1.Lines.Add(DriveLetter + ' Fixed Drive') ;
    DRIVE_REMOTE:
     Memo1.Lines.Add(DriveLetter + ' Network Drive') ;
    DRIVE_CDROM:
     Memo1.Lines.Add(DriveLetter + ' CD-ROM Drive') ;
    DRIVE_RAMDISK:
     Memo1.Lines.Add(DriveLetter + ' RAM Disk') ;
    end;
  end;
end;

Open in new window

Commented:
rename Memo1.Lines.Add to ComboBox1.Items.Add

and you will have them all in Combobox :)

Commented:
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

Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

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

[DELPHI] - Get Drives And Types
http://www.vbforums.com/showthread.php?t=346506

Commented:
hehe same code but not from there :)

I think i got it from here

Commented:
sorry wrong link this is the correct http://delphi.about.com/cs/adptips1999/a/bltip0599_5.htm :)
Ephraim WangoyaSoftware Engineer

Commented:
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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial