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

This should be simple, but I can't find it.

On win32, I'm looking for a way (preferably without installing new modules) to find the name of a drive.

For example, if my c: drive is called "windows", I want to be able to get the name "windows" by specifying "c:".

Any help would be appreciated.

Replies are listed 'Best First'.
Re: win32 drive name
by BrowserUk (Patriarch) on Nov 26, 2002 at 06:12 UTC

    E:\Perl\bin>perl -e" print `vol $ARGV[0]`=~/is \b(.+)\b/" c: 8C87-E163 E:\Perl\bin>perl -e" print `vol $ARGV[0]`=~/is \b(.+)\b/" d: Winnt E:\Perl\bin>perl -e" print `vol $ARGV[0]`=~/is \b(.+)\b/" e: B41D-3949 E:\Perl\bin>

    Okay you lot, get your wings on the left, halos on the right. It's one size fits all, and "No!", you can't have a different color.
    Pick up your cloud down the end and "Yes" if you get allocated a grey one they are a bit damp under foot, but someone has to get them.
    Get used to the wings fast cos its an 8 hour day...unless the Govenor calls for a cyclone or hurricane, in which case 16 hour shifts are mandatory.
    Just be grateful that you arrived just as the tornado season finished. Them buggers are real work.

      ok. `vol` seems to work for local drives only. I guess I need to be more specific.

      I use Clearcase on windows, and when I start a view, it is assigned a drive letter, usually starting at Z: and going backwards.

      In the explorer window, I see "my_view_name on 'view' (Z:)" Also, if I click Priorities, the same text appears in the 'label' textbox.
      But `vol` just tells me "CCase".

      Maybe there is some abstract clearcase command I need.

        In that case, I'd take a look at Win32::DriveInfo::VolumeInfo ( drive ); It comes as a part of the standard AS 5.6.1 distribution. I don't hold out great hope, as from your description, is seems that the info you are seeing is probably some trickery, but it's worth a shot.

        The other possibility would be to try using Win32::OLE and get the info from ClearCase (whatever that is:).

        Good luck.


        Okay you lot, get your wings on the left, halos on the right. It's one size fits all, and "No!", you can't have a different color.
        Pick up your cloud down the end and "Yes" if you get allocated a grey one they are a bit damp under foot, but someone has to get them.
        Get used to the wings fast cos its an 8 hour day...unless the Govenor calls for a cyclone or hurricane, in which case 16 hour shifts are mandatory.
        Just be grateful that you arrived just as the tornado season finished. Them buggers are real work.

Re: win32 drive name
by Zaxo (Archbishop) on Nov 26, 2002 at 08:59 UTC

    Take a look at File::Spec, it's in the standard distro.

    After Compline,
    Zaxo

(tye)Re: win32 drive name
by tye (Sage) on Nov 26, 2002 at 15:54 UTC

    Here is one way:

    #!/usr/bin/perl -w use strict; use Win32API::File qw( getLogicalDrives GetVolumeInformation ); for my $root ( @ARGV ? @ARGV : getLogicalDrives() ) { my( $vol, $ser, $maxlen, $bits, $fs ); $root .= ":" if length($root) < 2; $root .= "/" if length($root) < 3; if( ! GetVolumeInformation( $root, $vol, [], $ser, $maxlen, $bits, $fs, [] ) ) { warn "Can't get information about $root: $^E\n"; } else { print "$root is $fs named ($vol)\n"; } }
    or, more specifically:
    #!/usr/bin/perl -w use strict; use Win32API::File qw( GetVolumeInformation ); sub getVolumeLabel { my( $root )= @_; $root .= ":" if length($root) < 2; $root .= "/" if length($root) < 3; my $vol; GetVolumeInformation( $root, $vol, [], [], [], [], [], [] ) or undef $vol; return $vol; } for my $root ( @ARGV ) { my $label= getVolumeLabel($root); if( defined $label ) { print "$root is ($label).\n"; } else { warn "Can't get label for $root: $^E\n"; } }
    Yes, you should already have Win32API::File, so you shouldn't have to install a new module, whiner. ;)

            - tye
      Can't locate Win32API/File.pm in @INC (@INC contains: D:/Perl/lib D:/Perl/site/lib .)

      Unfortunately, I (and my co-workers) are forced to use an older version of perl (5.005_03) which doesn't seem to have that module. :(

      I only whine because this will be part of a script that will be used by many, and requiring everyone to install a new module is painful - especially since we're behind a firewall and most of the group are not fluent in installing modules. double :(
        Have you considerd useing perl2exe.
        You could go to the latest perl and what ever modules you want.
        It wraps modules in to the executiable.
        And only 1 file to copy and your done.
        Give it a try here is the link.