sum

指定した拡張子のファイルサイズの総計を表示するPerlスクリプトを作った。

@rem = '--*-Perl-*--
@echo off
if "%OS%" == "Windows_NT" goto WinNT
perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
goto endofperl
:WinNT
perl -x -S %0 %*
if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl
if %errorlevel% == 9009 echo You do not have Perl in your PATH.
if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul
goto endofperl
@rem ';
#!/usr/bin/perl -w
#line 15
# sum.pl
# Last Modified:Sun, 07 Dec 2003 23:28:47 +0900
#
#
#
#

use strict;
my $sum_file;
my @arg = @ARGV;

opendir(DIR, ".");
my @dirlist = readdir(DIR);

foreach my $arg (@arg) {
  chomp($arg);
  my $pattern = ".*\\.$arg\$";  # *.suffix$
  my @target = grep{/$pattern/} @dirlist;
  foreach my $file (@target) {
    my @stat = stat($file);
    my $size = $stat[7];
    $sum_file += $size;
  }
}

print $sum_file;
# sum.pl ends here.

__END__
:endofperl

上の中身をsum.batなどの名前にして、パスの通ったところにおく。そして、

sum exe dll

などとすると、カレントディレクトリ内のexeとdllの総計を表示する。

2052096

とかいう風に返ってくるはず。

エラー処理とかはやってないんで注意。(opendirとかreaddirが対象になるくらいだと思うけれど。)