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

Hi guys I have developed a small application that can search through directories for the kwyword provided by the user. But i want to have search to be done on all physical drives ((E.g) C: , D:)in windows can you please suggest how can i find what are the drives available in windows.thank you

Replies are listed 'Best First'.
Re: how to identify the windows drives
by bobf (Monsignor) on Aug 23, 2006 at 05:14 UTC

    Try Win32::DriveInfo. The DrivesInUse routine returns an array of all drive-letters in use.

    Update: I ran this little test on my system

    use strict; use warnings; use Win32::DriveInfo; my @drives = Win32::DriveInfo::DrivesInUse(); print join( "\n", @drives );
    Output:
    A C D

Re: how to identify the windows drives
by ikegami (Patriarch) on Aug 23, 2006 at 05:24 UTC
    You could use WMI. The "table" Win32_LogicalDisk contains the desired information.
    use Win32::OLE qw( in ); my $wmi_service = Win32::OLE->GetObject("winmgmts:{impersonationLevel= +impersonate}!\\\\.\\root\\cimv2") or die("Unable to connect to WMI: $!\n"); # DriveType 3 = local hard disk my $disk_col = $wmi_service->ExecQuery(" SELECT DeviceID FROM Win32_LogicalDisk WHERE DriveType = 3 "); my @drives = map { $_->DeviceID } in $disk_col; local $, = ", "; local $\ = "\n"; print @drives;

    On my computer, the above prints C:, D:, E:.
    If I remove the WHERE clause, it prints A:, B:, C:, D:, E:, F:, G:, H: (Floppy drives, hard drives, optical drives, USB drives, network drives, virtual drives, etc.)

Re: how to identify the windows drives
by planetscape (Chancellor) on Aug 23, 2006 at 13:01 UTC
Re: how to identify the windows drives
by Anonymous Monk on Aug 23, 2006 at 06:57 UTC
    sub drives { my @drives = (); eval{require Win32API::File;}; return map {"$_:\\"} ('C' .. 'Z') if $@; my @r = Win32API::File::getLogicalDrives(); return unless @r > 0; for (@r) { my $t = Win32API::File::GetDriveType($_); push @drives, $_ if ($t == 3 or $t == 4); } return @drives > 0 ? @drives : undef; }