Mega Code Archive

 
Categories / Delphi / System
 

Getting a list of the available drives on a system

Title: Getting a list of the available drives on a system Question: Is there a fast way to get a list of the available drives on a system? Answer: The following example demonstrates getting a list of the available logical drives available on the system. procedure TForm1.Button1Click(Sender: TObject); var ld : DWORD; i : integer; begin ld := GetLogicalDrives; for i := 0 to 25 do begin if (ld and (1 shl i)) 0 then Memo1.Lines.Add(Char(Ord('A') + i) + ':\'); end; end; and the list of names: var Buffer: array[0..500] of char; hChar: Char; begin GetLogicalDriveStrings(Sizeof(Buffer), Buffer); hChar:= Buffer; while hChar[0] #0 do begin ListBox1.Items.Add(hChar); hChar := StrEnd(hChar) + 1; end; end;