
Perl has some basic file and folder functions, like opendir and readdir, that allow you to get a directory listing. ActiveState Perl includes a Perl module called Win32::File, that allows you to retrieve attributes of a file or folder (including the compressed attribute). So the script uses readdir to get the folders at the root of the search, checks to compressed attribute and then recursively reads each subdirectory. If it finds a compressed folder, it writes the path to the log, and doesn't bother digging through that folder's subdirectories.
The script also demonstrates how fast Perl is. You'd be hard pressed to find anything that can do this faster.
use Win32::File;
$mydirname="c:"; print "Searching for compressed files in $mydirname/...\n"; open OUT,">compressionLog.txt";
&processDir($mydirname);
sub processDir{ my $bailOut=0; my ($dirname)=@_; $d=opendir(DIR,$dirname."/"); if($d){ $test=Win32::File::GetAttributes("$dirname", $attrs); if($attrs & COMPRESSED){ print "*** $dirname is compressed\n"; print OUT "$dirname is compressed\n"; $bailOut=1; } if($bailOut == 0){ my @subdirs=map ($_=$dirname."/".$_,(grep { !/\./ && !/\.\./ && -d "$dirname/$_" } readdir(DIR))); foreach $subdir (@subdirs){ if(index(lc($subdir),"dfsrprivate") == -1){ &processDir($subdir); } } } } }
close OUT;
No comments:
Post a Comment