This script will search the location for all .log files and compress them using NTFS.
#!perl
#Search osbLocations for *.log files and ntfs compress them.
use File::Find;
use Win32::OLE;
@osbLocations = (
'E:/obs-win-mthosting2',
'E:/obsr-win-mthosting3',
);
$strComputer = '.';
$objWMI = Win32::OLE->GetObject('winmgmts:\\\\' . $strComputer . '\\root\\cimv2');
foreach (@osbLocations)
{
find(\&processFile, $_);
}
sub processFile()
{
if ( -f and /.log$/ )
{
$objFile = $objWMI->Get('Cim_Datafile=\'' . $File::Find::name . '\'');
if ($objFile->Compressed != 1)
{
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";
}
}
}
}