Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Get Drive Letter (https://www.delphipraxis.net/163960-get-drive-letter.html)

sdean 23. Okt 2011 20:53

Delphi-Version: 7

Get Drive Letter
 
function GetDriveLetter(DriveIndex: Byte): PAnsiChar; stdcall; external 'GetDiskSerial.dll';

Hi , is there a way to get the Drive Letter from Drive Index ,
For example , when i enter 0 it will give me the current drive which is 'C:' and 'D:' .... etc

A pseudo function :

Delphi-Quellcode:
Function GetDriveLetter(DriveIdx:Byte):String;
begin
Result:=....DriveIdx ;
// Result will be 'C: D: ' if DriveIdx value is 0
end;
thank you .

omata 23. Okt 2011 21:17

AW: Get Drive Letter
 
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;

himitsu 23. Okt 2011 21:22

AW: Get Drive Letter
 
oder
http://www.devlib.net/getdiskserial.htm
http://msdn.microsoft.com/en-us/libr.../aa381689.aspx

sdean 23. Okt 2011 21:34

AW: Get Drive Letter
 
Zitat:

Zitat von omata (Beitrag 1132092)
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'

omata 23. Okt 2011 21:48

AW: Get Drive Letter
 
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;
Zitat:

Zitat von sdean (Beitrag 1132095)
... 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.

ATS3788 30. Jun 2012 07:35

AW: Get Drive Letter
 
himitzu
hat da einen link gesetzt

Frage
http://msdn.microsoft.com/en-us/libr...rot.10%29.aspx

Kann man das für Delphi brauchbar machen.:|

omata 9. Jul 2012 07:08

AW: Get Drive Letter
 
Zitat:

Zitat von ATS3788 (Beitrag 1173026)
Kann man das für Delphi brauchbar machen.:|

Für IVdsAdvancedDisk direkt habe ich jetzt nichts. Aber folgendes (über WMI) fand ich ganz interessant klick.

ATS3788 31. Okt 2012 08:47

AW: Get Drive Letter
 
Danke:thumb:


Alle Zeitangaben in WEZ +1. Es ist jetzt 05:31 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz