?
Solved

Detecting partitions on a drive

Posted on 1999-07-19
6
Medium Priority
?
153 Views
Last Modified: 2010-04-06
I have a program that searches for a certain type of file.  I need to have the program detect any partitions on the drive in addition to the primary partition (c) such d, e, etc. so that I can pass those drive letters to my search routine.
0
Comment
Question by:Orca
[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
6 Comments
 
LVL 17

Accepted Solution

by:
inthe earned 300 total points
ID: 1389719
do something like this:
it will search all the drives for the file of type.dll for instance:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    ComboBox1: TComboBox;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure GatherFiles(Const Lines: TStrings; Const Dir,Match: String);
var
  Rec: TSearchRec;
  Found: Integer;
Begin
  // Add files
  Found:= FindFirst(Dir+'\'+Match, faAnyFile, Rec);
  While Found = 0 do
  begin
    If (Rec.Attr AND faDirectory) = 0 Then Lines.Add(Dir+'\'+Rec.Name);
    Found := FindNext(Rec);
  End;
  FindClose(Rec);
  // Find directories (Without match)
  Found:= FindFirst(Dir+'\*.*', faAnyFile, Rec);
  While Found = 0 do
  begin
    If ((Rec.Attr AND faDirectory)>0) AND
       (Rec.Name<>'.') AND
       (Rec.Name<>'..') Then GatherFiles(Lines,Dir+'\'+Rec.Name,Match);
    Found := FindNext(Rec);
  End;
  FindClose(Rec);
End;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ComboBox1.items.Clear;
  GatherFiles(ComboBox1.Items,'','*.dll');
  If ComboBox1.Items.Count>0 Then
    ComboBox1.Text:= ComboBox1.Items[0];
  ShowMessage('Found '+IntToStr(ComboBox1.Items.Count)+' matching files.');
end;

end.
0
 
LVL 15

Expert Comment

by:simonet
ID: 1389720
inthe, I don't think that's what Orca wants. I think he wants to know what are the letters for the local drives.

Orca, if inthe routine's not what you want, you can reject it.

Do you really mean partitions?

Let's suppose I have 2 physical HDs plus a few more devices:

HD1 is drives C, E, F and G
HD2 is drive D
CDROM is drive H
ZIP is drive I

Do you want to get the letters for all the local drives or only for the partitions on HD1 (C, E, F, G)?

If what you want is the letter of all available local drives, then there are a few API calls that will work for you:

GetLogicalDriveStrings  and GetDriveType.

Here's an example of how to use them:

var
  pDrives : pchar;
  NumDrives : cardinal;
  i : integer;
  root : string;
begin
      Result := '';
      GetMem(pDrives, 1024);
  try
     NumDrives := 1023;
     NumDrives := GetLogicalDriveStrings(NumDrives, pDrives);
     NumDrives := NumDrives  div 4;
     for i := 0 to NumDrives do
     begin
        Root := string(pchar(pDrives+i*4));
        if GetDriveType(pchar(Root))=DRIVE_FIXED  then
        begin
           // Your search routine goes here!!!
           // The drive pointed by "root" is a local fixed drive.
        end;
     end;
  finally
     FreeMem(pDrives);
  end;
end;

Yours,

Alex
0
 
LVL 17

Expert Comment

by:inthe
ID: 1389721
yeh but using the search routine i gave you wouldnt need to pass any drive letters as it searches all drives anyway..
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 3

Expert Comment

by:bryan7
ID: 1389722
hmm, how do you avoid Win NT to show up a message because there's no disk in drive A ?
0
 
LVL 17

Expert Comment

by:inthe
ID: 1389723
try somethin like so:

var
  NoBox: Word;
begin
 NoBox := SetErrorMode(SEM_FailCriticalErrors);
  try
  {search code}
  except
  {your error code}
  end;
  SetErrorMode(NoBox);
end;

0
 

Author Comment

by:Orca
ID: 1389724
Thanks for all of the great information.

Between inthe's suggestions and Alex, I was able to do exactly what I wanted.  You guys were a huge help.

Thanks again.
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

718 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