Perform an action on several files at once (Perl)

This code can be found in Chapter 8 of Windows XP Cookbook

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the Perl code from this site.

# From the book "Windows XP Cookbook"
# ISBN: 0596007256

# This code shows how to iterate over all the zip files on a system
# ------ SCRIPT CONFIGURATION ------

use Win32::OLE qw(in);

$strComputer = '.';
$strExtension = 'zip';
# ------ END CONFIGURATION ---------
$objWMI = Win32::OLE->GetObject('winmgmts:\\\\' . $strComputer . '\\root\\cimv2');
$colFiles = $objWMI->ExecQuery('select * from Cim_DataFile ' . ' where extension = \'' . $strExtension . '\'');
print "Files with a .$strExtension extension:\n";
$intCount = 0;
foreach my $objFile (in $colFiles) {
    print ' ' . $objFile->Name, "\n";

    # Do some action here

    $intCount = $intCount + 1;
}
print "Total: $intCount\n";

This code has been viewed 676 times.

New from the creators of TechTasks.com: StatSheet.com