Dear seekers of Perl wisdom,

for a program running on a Windows OS I want to have a list of all device letters for devices containing a browsable directory structure (eg. "c:", "d:", etc).

This can be done by creating all possible drive letters and testing whether the respective drive letter is available as a drive. I wrote a function doing exactly that:

sub DriveList { my (@Drives,$Char); $Char = "b"; until ($Char eq "z") { ++$Char; if ((-d "$Char:\\") && (-w "$Char:\\")) { push(@Drives,sprintf("%s:",$Char)); } } @Drives; }

This works quite fine, except for those drives containing floppys: if there is no floppy inserted a window will pop up saying that a floppy has to be inserted, and that is obviously annoying. One possibility would be to just exclude letters "a:" and "b:", which are usually reserved for the floppys (as I did in the function above) - rather a workaround than a solution.

Now, this would still be good enough for me, but I recently found out that inserted UMTS sticks can have the same effect, so again an error window pops up, asking for the insertion of a data medium - and they won't have a letter I can exclude, but can appear anvwhere in the list of possible characters.

Could anybody tell me how to change my function to be equipped to deal with those floppy and USB device problems? Or even suggest a real solution?

Many thanks in advance, and wishing you all a good time, Yours

chanklaus


Learning is like swimming against the current - as soon as you stop you'll drift back
(Chinese proverb)

In reply to Creating a drive list on a Windows system? by chanklaus

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.