Solved

Delphi Programming question

Posted on 1997-07-01
6
153 Views
Last Modified: 2010-04-04
Hello,I want to get a list of available drives, preferabily with drive types with delphi 2.0.I have found the relevent API calls but was wondering if there was an delphi function call to do this?
0
Comment
Question by:essbb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 1

Accepted Solution

by:
kevinb062397 earned 60 total points
ID: 1338051
Here's a app you can try.  This works on all drives. The second snip on code is for network drives info.


Start a new app.  add 1 button, 1 edit box, 1 label.  Copy the code into it and run.

procedure TForm1.Button1Click(Sender: TObject);
Var
x:integer;
drivetype:integer;
begin
for x:= 65 to (65+25)  do begin
edit1.text := chr(x) + ':';
drivetype := getdrivetype(pchar(edit1.text));
case drivetype of
0:Label1.caption := 'Drive Type Not Determined';
1:Label1.caption := 'Root Does not exists';
DRIVE_REMOVABLE:Label1.caption := 'Removable Drive';
DRIVE_FIXED:Label1.caption := 'Fixed Drive';
DRIVE_REMOTE:Label1.caption := 'Remote Drive';
DRIVE_CDROM:Label1.caption := 'CD Drive';
DRIVE_RAMDISK:Label1.caption := 'RamDisk Drive';
end;
update;
sleep(500);
end;
end;

-----------------------------------------------------------------

   s1 := TStringList.Create;
   nMappingsCount := GetNetworkDriveMappings(s1);
   for i := 0 to nMappingsCount -1 do begin
      listbox2.items.add(s1[i]);
   end;
   s1.free;
   getinfo;
   filefind;
   refresh;
end;


Function TForm1.GetNetworkDriveMappings(s1:TStrings):integer;
Var
   i:Integer;
   sNetPath:String;
   dwMaxNetPathLen:DWord;
Begin
   s1.clear;
   dwMaxNetPathLen := MAX_PATH;
   SetLength(Snetpath,dwMaxNetPathLen);
   For i := 0 to 25 do
   Begin
      if (NO_ERROR = Windows.WNetGetConnection(Pchar('' + Chr(65 + i) + ':'),
      Pchar(sNetPath), dwMaxNetPathLen))
      Then Begin
         s1.add(Chr(65 + i) + ':' + sNetPath);
      end;
   end;
   Result := s1.count;
end;

Let me know if you need more.
0
 

Author Comment

by:essbb
ID: 1338052
Thanks!
0
 

Author Comment

by:essbb
ID: 1338053
Do you know why the drive that the program is running from comes up as 'root not found' unless you are running the program from the root directory?Is it an API Bug?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:kevinb062397
ID: 1338054
It could be... You might try changing directories to the root of each drive before you getdrivetype.  Since the function uses the drive letter (i.e. C: ) it might be actual giving it the current directory.

I'm curious now, Thanks for the bit of info.
I'm going to try a few things myself.  I'll let you know if I find anything.

0
 
LVL 1

Expert Comment

by:kevinb062397
ID: 1338055
I added this just befor the getdrivetype:

{$I-}
chdir(edit1.text + '\');
{$I+}
if IOResult = 0 then begin

It listed all the drives correctly.

See if it will work for you.  ????
0
 

Author Comment

by:essbb
ID: 1338056
Yeah, That makes sense but you only need do it on the drive that the program is running on, If you go into the other drives first and change dir down a few levels it still works. Must be an API bug I think.btw - the getDriveType also works for all my networked drivesThanks-Brett
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
code issue 8 185
Firemonkey allowing RTL on android 6 56
Delphi android app hide keyboard 3 45
Get monday of current week where a week always starts on monday 2 20
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question