Dermot Paikkos wrote:

> Hi there,
> 
> SYS stuff: Active perl 626 on Win32.
> 
> I want to get the volume name of a CD ROM. I have tried stat and 
> lstat but this doesn't return the volume label/name.
> 
> Do I need to install a module for this or can it be scripted? If it's the 
> latter, what should I use?


You may be able to do it on NT with Win32::AdminMisc, but if not and
for 9x - example using Win32::API (lightly tested):

use strict;
use Win32::API;

my $GetVolInfo = new Win32::API("kernel32", "GetVolumeInformation",
   [qw(P P N P P P P N)], 'N') or
   die 'GetVolumeInformation: ' . Win32::FormatMessage(Win32::GetLastError());

print "Drive VolName          Ser#       Flags    FS\n";
print "----- -----------  -----------  --------  ----\n";

foreach ('C' .. 'Z') {

        my $lpRootPathName = "$_:\\";
        my $lpVolumeNameBuffer = pack 'A*', "\0" x 256;
        my $nVolumeNameSize = 255;
        my $lpVolumeSerialNumber = pack 'I', 0; # "\0" x 256;
        my $lpMaximumComponentLength = pack 'I', 0;
        my $lpFileSystemFlags = pack 'I', 0;
        my $lpFileSystemNameBuffer = pack 'A*', "\0" x 256;
        my $nFileSystemNameSize = 255;

        my $ret = $GetVolInfo->Call($lpRootPathName, $lpVolumeNameBuffer,
          $nVolumeNameSize, $lpVolumeSerialNumber, $lpMaximumComponentLength,
          $lpFileSystemFlags, $lpFileSystemNameBuffer, $nFileSystemNameSize) or
          do {
                  print "GetVolInfo $_:\\: ",
                  Win32::FormatMessage(Win32::GetLastError());
                  next;
          };

        $lpVolumeNameBuffer =~ s/\0.*$//;
        $lpFileSystemNameBuffer =~ s/\0.*$//;

        printf " %s:   %-11.11s  %11u  %8x  %-s\n", $_,
          unpack ('A*', $lpVolumeNameBuffer),
          unpack ('I', $lpVolumeSerialNumber),
          unpack ('I', $lpFileSystemFlags),
          unpack ('A*', $lpFileSystemNameBuffer);
}

__END__





-- 
   ,-/-  __      _  _         $Bill Luebkert   ICQ=14439852
  (_/   /  )    // //       DBE Collectibles   Mailto:[EMAIL PROTECTED]
   / ) /--<  o // //      http://dbecoll.tripod.com/ (Free site for Perl)
-/-' /___/_<_</_</_     Castle of Medieval Myth & Magic http://www.todbe.com/

_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to