Advertisement
TLama

Untitled

Nov 28th, 2014
450
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.01 KB | None | 0 0
  1. type
  2.   TDriveType = (
  3.     dtUnknown,
  4.     dtNoRootDir,
  5.     dtRemovable,
  6.     dtFixed,
  7.     dtRemote,
  8.     dtCDROM,
  9.     dtRAMDisk
  10.   );
  11.   TDriveTypes = set of TDriveType;
  12.  
  13. procedure GetDriveList(Drives: TStrings; Filter: TDriveTypes = []);
  14. var
  15.   P: PChar;
  16.   Buffer: string;
  17.   BufLen: Integer;
  18. begin
  19.   BufLen := GetLogicalDriveStrings(0, nil);
  20.   if BufLen > 0 then
  21.   begin
  22.     SetLength(Buffer, BufLen);
  23.     if GetLogicalDriveStrings(Length(Buffer), PChar(Buffer)) = 0 then
  24.       RaiseLastOSError;
  25.  
  26.     P := PChar(Buffer);
  27.     while StrLen(P) > 0 do
  28.     begin
  29.       if (Filter = []) or (TDriveType(GetDriveType(P)) in Filter) then
  30.         Drives.Add(P);
  31.       P := StrEnd(P) + 1;
  32.     end;
  33.   end
  34.   else
  35.     RaiseLastOSError;
  36. end;
  37.  
  38. // possible usage to list all drive types
  39. GetDriveList(ComboBox.Items);
  40. // possible usage to list fixed drive types
  41. GetDriveList(ComboBox.Items, [dtFixed]);
  42. // possible usage to list fixed and removable drive types
  43. GetDriveList(ComboBox.Items, [dtFixed, dtRemovable]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement