GetLogicalDrives 回傳 32 位元無號整數,第 0 位對應 A:,第 1 位對應 B:,以此類推。位元為 1 表示該磁碟機存在。比 GetLogicalDriveStrings 更輕量,適合只需判斷存在性的場合。
function GetLogicalDrives: DWORD; stdcall;
procedure TForm1.FormCreate(Sender: TObject);
var
Drives: DWORD;
i: Integer;
begin
Drives := GetLogicalDrives;
Memo1.Clear;
for i := 0 to 25 do
if LongBool(Drives and ($0001 shl i)) then
Memo1.Lines.Add(Char(Ord('A') + i) + ':\');
end;

$0001 shl i:產生只在第 i 位為 1 的遮罩。Drives and Mask:若結果非 0,表示該位為 1。LongBool(...):將非零整數轉為 True。搭配 GetDriveType 可進一步過濾磁碟機類型 (固定/可移除/網路/CD-ROM/RAM)。