use strict;
use File::Find;
print "输入你要计算文件数量所属目录的路径: \n";
chomp(my $dir = <STDIN>);
print "正在计算,请稍后...\n";
BEGIN{
my $count = 0;
sub count_num { $count++ if -f }
sub count_get { $count }
}
find(\&count_num,$dir);
print "$dir 目录下共有 " . &count_get( ) . " 个文件 \n";
system('pause');
![](https://img-my.csdn.net/uploads/201301/04/1357267134_9504.jpg)