Forum > Windows

show available drives [SOLVED]

(1/2) > >>

bjlockie1:
I'm trying to list available drives.
These functions show 3 letters, C, D, Z.
It can't ChDir to drive D:\ but C:\ and Z:\ work fine.
I don't think drive D: should be listed.
I am not a Windows programmer so I cobbled this code together.



--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function GetBit(Value: QWord; Index: Byte): Boolean;begin  Result := ((Value shr Index) and 1) = 1;end; function GetDriveLetters(): TStringList;{$ifdef Windows}var dword     : QWord;    letter    : Char;    i         : Byte = 0;    shortname : String;{$endif}begin    Result:=TStringList.Create();    {$ifdef Windows}        dword:=GetLogicalDrives();         for letter:='A' to 'Z' do        begin            if GetBit(dword,i)=True then            begin                shortname:='(DRIVE) '+letter+':\';                Result.Add( shortname );            end;            i:=i+1;        end;    {$endif}end;

Remy Lebeau:

--- Quote from: bjlockie1 on November 20, 2020, 10:20:24 pm ---It can't ChDir to drive D:\ but C:\ and Z:\ work fine.

--- End quote ---

What kind of drive is D:\ exactly?  What does GetDriveType() report for it?  Is it a partition on an HDD/SSD?  Is it a CD/DVD disc drive?  Is it a removable USB drive?  Is it a network drive share?

440bx:

--- Quote from: bjlockie1 on November 20, 2020, 10:20:24 pm ---I'm trying to list available drives.
These functions show 3 letters, C, D, Z.
It can't ChDir to drive D:\ but C:\ and Z:\ work fine.
I don't think drive D: should be listed.

--- End quote ---
The fact that Windows allocated a letter to a drive does not always imply the drive is accessible.  That's why @Remy Lebeau above was asking for the drive type.

You can find an example of showing the available drives and their type at https://forum.lazarus.freepascal.org/index.php/topic,44377.msg311910.html#msg311910

But, again, the fact that a letter/drive is listed does _not_ mean it is accessible.

HTH.

winni:

--- Quote from: bjlockie1 on November 20, 2020, 10:20:24 pm ---I'm trying to list available drives.


--- End quote ---

Why do you start a new topic with the same issue
while the other topic is still active??

bjlockie1:

--- Quote from: winni on November 21, 2020, 02:32:58 am ---Why do you start a new topic with the same issue
while the other topic is still active??

--- End quote ---

The other topic was in the Linux forum.
I said I was coming here to hopefully get more Windows specific help.
Was that wrong?

Navigation

[0] Message Index

[#] Next page

Go to full version