Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Removable Device

Posted on 2004-11-01
4
Medium Priority
?
230 Views
Last Modified: 2010-07-27
Hi there,

I wonder if anyone could tell me how to determine if a "drive" is a removable device - such as a USB Memory Key ?
I'm using D6.

DR
0
Comment
Question by:DelRunner
[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
4 Comments
 
LVL 7

Expert Comment

by:sftweng
ID: 12470314
Reply-To: "Todd M. Eischeid" <eischeid@erols.com>
From: "Todd M. Eischeid" <eischeid@erols.com>
Newsgroups: borland.public.delphi.objectpascal
References: <b5tmbu864ipn93mofigjaq79aubvft905l@4ax.com> <3cbbca7f$1_1@dnews>
Subject: Re: How to tell if a drive is Iomega Zip Drive?
Date: Wed, 17 Apr 2002 17:13:56 -0400
Lines: 165
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4522.1200
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200
NNTP-Posting-Host: 208.59.196.112
Message-ID: <3cbde52e_1@dnews>
X-Trace: dnews 1019077934 208.59.196.112 (17 Apr 2002 14:12:14 -0700)
Path: dnews
Xref: dnews borland.public.delphi.objectpascal:238032

Eric,

Below are a set of functions I wrote to Delphi-ize the Win API functions for
drive information. For Zip drives the type will be dtRemovable and
TDriveInfo.DiskSize will return a number around 98078 (but only if there is
a zip disk in the drive; otherwise the DiskSize value will be zero)

Regards,
Todd Eischeid

********************************

type TDriveType = (dtUnknown, dtDoesNotExist, dtRemovable, dtFixed,
dtNetwork, dtCDROM, dtRAMDisk);

type TDriveInfo = record
   DriveLetter: string;
   DriveType: TDriveType;
   TypeDescrip: string;
   DriveSize: single;  //size in Kilobytes
   DriveFreeSpace: single; //free space in Kilobytes
end;

type TDriveInfoArray = array of TDriveInfo;


//pass a single character string as the 'DriveLetter' param
function DriveType(DriveLetter: string): TDriveType;
var
  x,
  DrvType   : Integer;
  DrvLetter,
  DrvString : String;
begin

    result := dtUnknown;
    DriveLetter := DriveLetter + ':\';

    // get the drive type
    DrvType := GetDriveType(pChar(DriveLetter));

    // set our drive type string accordingly
    case DrvType of
      0                 : result := dtUnknown;
      1                 : result := dtDoesNotExist;
      DRIVE_REMOVABLE  : result := dtRemovable;
      DRIVE_FIXED : result := dtFixed;
      DRIVE_REMOTE : result := dtNetwork;
      DRIVE_CDROM : result := dtCDROM;
      DRIVE_RAMDISK : result := dtRAMDisk;
    end;


end;


//returns a listing of all drives and types on the system
procedure GetAllDriveTypes(var DriveInfoArray: TDriveInfoArray);
var
  x: integer;

begin

DriveInfoArray := nil;
SetLength(DriveInfoArray, 0);

//25 possible drives ... a-z
for x := Ord('A') to Ord('Z') do
begin
   if not ( DriveType(Chr(x)) = dtDoesNotExist) then
   begin
      SetLength(DriveInfoArray, Length(DriveInfoArray) + 1);
      DriveInfoArray[Length(DriveInfoArray) - 1].DriveLetter := Chr(x);
      DriveInfoArray[Length(DriveInfoArray) - 1].DriveType :=
DriveType(Chr(x));
      DriveInfoArray[Length(DriveInfoArray) - 1].TypeDescrip :=
DriveTypeToString(DriveInfoArray[Length(DriveInfoArray) - 1].DriveType);
      DriveInfoArray[Length(DriveInfoArray) - 1].DriveSize := DiskSize(x -
64) / 1024;  //size in KB
      DriveInfoArray[Length(DriveInfoArray) - 1].DriveFreeSpace :=
DiskFree(x - 64) / 1024;  //size in KB
   end;


end;


end;


function DriveTypeToString(DriveType: TDriveType): string;
begin

case DriveType of
   dtUnknown: result := 'Unknown Drive Type';
   dtDoesNotExist: result := 'Drive Does Not Exist';
   dtRemovable: result := 'Removable Drive';
   dtFixed: result := 'Fixed Drive';
   dtNetwork: result := 'Network Drive';
   dtCDROM: result := 'CD-ROM Drive';
   dtRAMDisk: result := 'RAM Disk Drive';

end;

end;



//Returns true if the drive is ready (useful for removable drives)
function DriveReady(DriveLetter: string): boolean;
var
  code: Integer;
  rec: TSearchRec;
  EMode: Word;

begin

 EMode := SetErrorMode(SEM_FAILCRITICALERRORS);

 DriveLetter := AnsiLowerCase(DriveLetter);

 //FYI,  ord('a') = 97

 try
   result := (DiskSize( Ord(DriveLetter[1]) - 96 ) <> -1)
  finally
   SetErrorMode(EMode);
 end;




end;



***********************************************



"Eric Jansen" <eric@do.not.spam.keyword.nl> wrote in message
news:3cbbca7f$1_1@dnews...
> "Gene Weinbeck" <gene@fundraisersoftware.com> wrote in message
> news:b5tmbu864ipn93mofigjaq79aubvft905l@4ax.com...
> > Is there a way to determine if a drive is an Iomega Zip drive?  or any
> > other high-capacity removable media?
> >
>
> GetDriveType will tell you if the disk is removable, GetDiskFreeSpace(Ex)
> the disk size.
>
> hth
> --
> Eric Jansen
>
> Find your answers at:
> Newsgroups archives:   http://groups.google.com
> Torry's Delphi Pages:   http://www.torry.net
> Delphi Super Page:   http://delphi.icm.edu.pl
0
 
LVL 7

Accepted Solution

by:
sftweng earned 1000 total points
ID: 12470326
0
 
LVL 1

Author Comment

by:DelRunner
ID: 12488153
Excelent, workes great - thanks.
0
 
LVL 7

Expert Comment

by:sftweng
ID: 12488243
A pleasure; I'm pleased to have been of help.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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

618 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