in reply to win32 drive name
Here is one way:
or, more specifically:#!/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"; } }
Yes, you should already have Win32API::File, so you shouldn't have to install a new module, whiner. ;) - tye#!/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"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (tye)Re: win32 drive name
by xafwodahs (Scribe) on Nov 26, 2002 at 16:08 UTC | |
by Three (Pilgrim) on Nov 26, 2002 at 17:01 UTC |