0 Replies - 1487 Views - Last Post: 16 January 2009 - 08:42 PM

#1 NickDMax   User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2255
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

List Windows Drives from Perl

Posted 16 January 2009 - 08:42 PM

Description: Note if you have Oracle installed you have to blank the Perl5Lib environment variable before using the Win32 lib.An intro to Win32::OLE and the windows scripting runtime.
#Perl Example for using the Scripting.FileSystemObject
use Win32;
use Win32::OLE 'in'; #used to convert a collection to an array.
#Enumeration of drive types.
my @driveTypes = ("Unknown", "Removable", "Fixed", "Network", "CDRom", "Ram Disk");

#Get the Scripting FileSystemObject -- this is the entry point
my $obj = "Scripting.FileSystemObject";
my $fs = Win32::OLE->new($obj); #create a new version of the object.

#Request a collection of all drives...
my $drives = $fs->Drives;

#Get the count = #of drives
my $max = $drives->{count};

#print a report
print "Drive Letter Report:n";
print "Number of Drives: " . $max . "n";
foreach my $drv ( in($drives)) {
	$typ = $drv->{DriveType};
	my $size = sprintf("%3.2f", $drv->{TotalSize}/(1073741824)); #Calculate in GBs
	print $drv->{DriveLetter} . ": - " . "$driveTypes[$typ] - $size GBn";
	
}


Is This A Good Question/Topic? 0
  • +

Page 1 of 1