I have the following script that I use to determine drive types. Most USB drives return as a Removable Drive type, but the Lexar Jumpdrive returns as a Fixed Drive. Does anyone know of a better way to determine if a removable drive is plugged in to the computer (Camera, USB Drive, etc)? Is there a way to determine if a removable drive is a USB drive?
use strict; use Win32::API; $|=1; binmode(STDOUT); getDrivesInUse(); ############### sub getDrivesInUse{ my (@dr, $i); my %DriveType=( 1=>"Unknown Root", 2=>"Removable", 3=>"Fixed", 4=>"Mapped", 5=>"CDRom", 6=>"RAMDisk", ); my $GetLogicalDrives = new Win32::API("kernel32", "GetLogicalDrive +s", [], 'N') || return $^E; my $bitmask = $GetLogicalDrives->Call(); print "bitmask:\r\n$bitmask\r\n\r\n"; for $i(0..31) { if ($bitmask & 2**$i){ my $drive=chr(ord("A")+$i); my $type=getDriveType($drive); print "$i\. Drive: $drive [$type][$DriveType{$type}]\r\n"; } } } ############### sub getDriveType ($) { my $drive = shift; return undef unless $drive =~ s/^([a-z])(:(\\)?)?$/$1:\\/i || $dri +ve =~ s/^(\\\\\w+\\\w+\$?)(\\)?$/$1\\/; my $GetDriveType = new Win32::API("kernel32", "GetDriveType", ['P' +], 'N') or return; my ($lpDirectoryName) = $drive; my $type = $GetDriveType->Call( $lpDirectoryName ); return $type; }

-------------------------------
by me
http://www.basgetti.com
http://www.kidlins.com


In reply to Detecting a Lexar Jumpdrive by slloyd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.