Compress a folder with NTFS compression (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

# ------ SCRIPT CONFIGURATION ------

use Win32::OLE;

$strComputer = '.';
$strFile = '<FilePath>';
# e.g. d:\scripts\test.vbs
# ------ END CONFIGURATION ---------
$objWMI = Win32::OLE->GetObject('winmgmts:\\\\' . $strComputer . '\\root\\cimv2');
$objFile = $objWMI->Get('Cim_Datafile=\'' . $strFile . '\'');
print $objFile->Name, "\n";
$intRC = $objFile->Compress;
# To uncompress change this to objFile.Uncompress
if ($intRC != 0) {
    print 'There was an error compressing the file: ' . $intRC, "\n";
}
else {
    print "File compression successful\n";
}

This code has been viewed 903 times.

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