Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Getting list of drives on pc

by Coruscate (Sexton)
on Apr 16, 2003 at 20:49 UTC ( [id://251043]=note: print w/replies, xml ) Need Help??


in reply to Getting list of drives on pc

I once had the same need and didn't even think of asking about a module, nor did I look at the Win32:: set of modules. So I did my own little snippet, that went something like this. I think this was it, I don't have a windows box to test it on anymore, so you know... it might not be right.

my @drives; for my $drive ('A' .. 'Z') { opendir DRIVE, "$drive:/" and push @drives, $drive; } print "Drives: ", (join ', ', @drives), "\n";


If the above content is missing any vital points or you feel that any of the information is misleading, incorrect or irrelevant, please feel free to downvote the post. At the same time, please reply to this node or /msg me to inform me as to what is wrong with the post, so that I may update the node to the best of my ability.

Replies are listed 'Best First'.
Re: Re: Getting list of drives on pc
by dze27 (Pilgrim) on Apr 16, 2003 at 21:58 UTC
    I do have a Windows box to test it on and it looks like this largely works. A couple of notes though. My floppy drive is A:, and it brought up a message (twice! and I cancelled both times) indicating that there was no disk in the A: drive. This would be awkward for a non-interactive user. Second thing, my CD drive is D:, and it completely skipped over that when the drive was empty, not recognizing it at all. No error message, no nothing. However, with a CD in the drive, it recognized it the same was as for all the fixed drives. So, caveat emptor with removable-media drives.
      Many Windows installations have A:\ and B:\ aliased to the
      floppy drive, which is probably why you got the message 2x.

      blyman
      setenv EXINIT 'set noai ts=2'

      Ah yes, I could have told you about the not recognizing the empty drive. It will only return a list of drives that currently have a filesystem mounted on it. It simply tries to open the root directory of the drive, and if executed successfully, adds it to the list. As for the alert telling you about the empty floppy drive, this I could have expected but did not see in my use of that snippet. I believe it's because I used it in a CGI script ;)


      If the above content is missing any vital points or you feel that any of the information is misleading, incorrect or irrelevant, please feel free to downvote the post. At the same time, please reply to this node or /msg me to inform me as to what is wrong with the post, so that I may update the node to the best of my ability.

      You can control whether trying to access an empty drive prompts the user. See Win32API::File's SetErrorMode() for details.

                      - tye
Re: Re: Getting list of drives on pc
by PodMaster (Abbot) on Apr 17, 2003 at 14:01 UTC
    I've seen Randy Kobes do that. Besides the CD issue, sometimes (never seen it in practice) you may need to
    for my $drive ( 'A' .. 'Z', 'AA' .. 'ZZ' ) {
    in case the logical drives number is really high ;)


    MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
    I run a Win32 PPM repository for perl 5.6x+5.8x. I take requests.
    ** The Third rule of perl club is a statement of fact: pod is sexy.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://251043]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2024-04-20 02:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found