Ok, a new Version...
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
Drive:=GetCurrentDir
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;
... and 1 will give drive 'C' which normally gives drive 'D'
This, I can't unterstand. I think if index = 0 gives you the CurrentDir, why should index = 1 gives you D. Than, it is an other work like this:
Delphi-Quellcode:
function GetDriveLetter(DriveIdx:byte):string;
var
vDrivesSize: Cardinal;
vDrives : array[0..128] of Char;
vDrive : PChar;
Drive:string;
Index:byte;
begin
Drive:='';
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;
Result:=copy(Drive, 1, 1);
end;
But this Code gives you no CurrentDir, it is an esay Drivelist.