Get a drive available list  

Send By: Radikal (Q3 Team)
Web : http://www.q3.nu
Email: radikal@q3.nu
Date: 24/07/00

Tip accessed 564 times

 


We can use GetLogicalDriveStrings that is filled a buffer with the names of the available units.
The problem is that the full thing in plan -character #0 so we will have to translate it to something to treat him with comfort from Delphi.

For example, we can use this procedure that fills a TStrings with the names of units:

 procedure TForm1.Button1Click(Sender: TObject);

   procedure PillaUnidades(Lista:TStrings);
   var
      Buffer  : Pchar;
      Largo   : integer;
      i       : integer;
      sTemp   : String;
   begin
     Largo:=GetLogicalDriveStrings(0,Buffer);
     GetMem(Buffer,Largo);
     GetLogicalDriveStrings(Largo,Buffer);
     sTemp:='';
     for i:=0 to Largo do
     begin
       if Buffer[i]<>#0 then sTemp:=sTemp+Buffer[i]
       else
         begin
           Lista.Append(sTemp);
           sTemp:='';
         end;
     end;
     Freemem(Buffer);
   end;
 begin
   PillaUnidades(Memo1.Lines);
 end;