kirk123 has asked for the wisdom of the Perl Monks concerning the following question:

Hi: Does anybody know a way to get a list of drives on window NT. I am traversing the directories tree like this: finddepth (\&rem_space,"c:\\","m:\\"); I don't want to type in "c:\\" or "m:\\" and so on. I want to use a variable that contain all the drives. Please help --kirk

Replies are listed 'Best First'.
Re: How to get a List of drives on window
by myocom (Deacon) on Aug 14, 2002 at 21:34 UTC

    Two modules spring to mind. Win32::DriveInfo is one, and Dave Roth's Win32::AdminMisc is the other. Both modules have functions that will return a list of drives: DrivesInUse() in the former, and Win32::AdminMisc::GetDrives() in the latter.

    "One word of warning: if you meet a bunch of Perl programmers on the bus or something, don't look them in the eye. They've been known to try to convert the young into Perl monks." - Frank Willison
(tye)Re: How to get a List of drives on window
by tye (Sage) on Aug 14, 2002 at 21:46 UTC

    Note that Win32API::File has a nice advantage over the other modules previously suggested in that it is part of libwin32 and so comes preinstalled with Win32 binary distributions of Perl.

    use strict; use Win32API::File qw( getLogicalDrives GetDriveType :DRIVE_ ); for my $root ( getLogicalDrives() ) { my $type= GetDriveType($root); if( DRIVE_FIXED == $type || DRIVE_RAMDISK == $type ) { .... } }
    Since you probably don't want to search the floppy, CD-ROM, unpartitioned, nor network drives.

            - tye (but my friends call me "Tye")
Re: How to get a List of drives on window
by blaze (Friar) on Aug 14, 2002 at 21:35 UTC
    I believe you can use Win32::DriveInfo, I know it works for win98, never tried on winNT
    #!/Perl/bin/perl -w use strict; use Win32::DriveInfo; my @drives = Win32::DriveInfo::DrivesInUse();
    should give you all the drives that are in use
    hth
Re: How to get a List of drives on window
by Marza (Vicar) on Aug 14, 2002 at 23:38 UTC

    I wrote a small script that does space checks which does what you ask. Look at Domain Disk space check for an example of yet another way to do it! ;)