Einzelnen Beitrag anzeigen

sdean

Registriert seit: 5. Dez 2009
64 Beiträge
 
#4

AW: Get Drive Letter

  Alt 23. Okt 2011, 22:34
Delphi-Quellcode:
function GetDriveLetter(DriveIdx:byte):string;
var
  vDrivesSize: Cardinal;
  vDrives : array[0..128] of Char;
  vDrive : PChar;
  Drive:string;
  Index:byte;
begin
  if DriveIdx = 0 then
    GetDir(DriveIdx, Drive)
  else begin
    vDrivesSize := GetLogicalDriveStrings(SizeOf(vDrives), vDrives);
    if vDrivesSize <> 0 then begin
      Index:=0;
      vDrive := vDrives;
      while (vDrive^ <> #0) and (Index < DriveIdx) do begin
        Drive:=StrPas(vDrive);
        Inc(vDrive, SizeOf(vDrive));
        inc(Index);
      end;
    end;
  end;
  Result:=copy(Drive, 1, 1);
end;
thank you omata for your help , but there's an issue :
if i enter 0 as DriveIdx value , it will give drive 'D' which normally gives 'C' .
and 1 will give drive 'C' which normally gives drive 'D'
  Mit Zitat antworten Zitat