[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Final step (?)



Oops sent a version of this, before it was done, to Strider,
via email... here's what I wound up with:

use Mac::Files;

$dir = "Internal:temp";
chdir $dir || die "Can't chdir $dir : $!";
&readDir( $dir );

sub readDir (){
	local($path) = @_;
	local($i);
	local($fil);
	opendir( DIR, $path ) || die "Can't open $path : $!";
	local(@fileList) = readdir( DIR );
	closedir( DIR );

	# Unless you change $[, Perl arrays are zero based...
	# $# is the index of the last item in the array, so
	# we need to add 1 to get the size of the array.
	$numFiles += $#fileList + 1;
	for ($i = 0; $i <= $#fileList; $i++) {
		$fil = "$path:$fileList[$i]";
		@info = stat($fil);
#		print "$fil($fileList[$i]) $info[2]\n";
		$has = FSpGetCatInfo($fil);
			# remember: directories are files, also... just special
			# ones that contain overhead, add them in to the size also.
		$total += $has->{ioFlLgLen} + $has->{ioFlRLgLen};
			# physical size is how many blocks (in bytes) the file takes
			# up and will be different on different sized volumnes. HFS
			# doesn't do frags (though, you'd still have a physical
			# size > logical size with frags.)
		$totalPhys += $has->{ioFlPyLen} + $has->{ioFlRPyLen};
		# file tests with '_' use the result of the last stat call.
		if(-d _) {
			&readDir( "$fil" );
		}
	}
}
print "$numFiles for $total(logical) bytes, $totalPhys(physical) bytes\n";

Tom Kimpton
--
Mrs. Bun: Have you got anything without spam?
Waitress: Well, there's spam egg sausage and spam, that's not got
much spam in it.
Mrs. Bun: I don't want any spam!



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch