Jump to content

[Delphi] List Drives And Their Types

- - - - -

  • Please log in to reply
No replies to this topic

#1
LuthfiHakim

LuthfiHakim

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 763 posts
The following procedure will fill AList with information (the letter and type of the drive) of currently available drives in the system.


interface

uses

  Windows

  , SysUtils

  , Classes

  ;


type

  TDriveType =

    (

      dtUnknown     = DRIVE_UNKNOWN

      , dtNoRootDir = DRIVE_NO_ROOT_DIR

      , dtRemovable = DRIVE_REMOVABLE

      , dtFixed     = DRIVE_FIXED

      , dtRemote    = DRIVE_REMOTE

      , dtCDROM     = DRIVE_CDROM

      , dtRAMDisk   = DRIVE_RAMDISK

    );


  PDrive=^TDrive;

  TDrive=record

    Letter: Char;

    Type_ : TDriveType;

  end;


  procedure EnumDrives(AList: TList);


implementation


procedure EnumDrives(AList: TList);

var

  r            : LongWord;

  vDriveLetters: array[0..128] of Char;

  vDriveLetter : PChar;

  vDrive       : PDrive;

  vDriveRoot   : string;

begin

    r := GetLogicalDriveStringsW(SizeOf(vDriveLetters), vDriveLetters);

    if r = 0 then exit;

    if r > SizeOf(vDriveLetters) then

      raise Exception.Create(SysErrorMessage(ERROR_OUTOFMEMORY));


    vDriveLetter := vDriveLetters;

    while vDriveLetter^ <> #0 do

    begin

      New(vDrive);

      vDrive.Letter   := vDriveLetter^;

      vDriveRoot      := vDriveLetter^ + ':\';

      vDrive.Type_    :=  TDriveType(Windows.GetDriveType(PChar(vDriveRoot)));

      AList.Add(vDrive);

      Inc(vDriveLetter, SizeOf(vDriveLetter));

    end;

end;


Edited by LuthfiHakim, 22 November 2010 - 04:58 AM.
remove drive type that is actually not detectable with the code





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users