perl 统计指定目录下的文件和目录数量

2255阅读 0评论2012-03-17 努力小伙
分类:Python/Ruby


点击(此处)折叠或打开

  1. #!/usr/bin/perl -w
  2. # name: total.pl
  3. # 统计目录下文件的数量、
  4. # 来源: Lover的工具小屋
  5. # author: Lover

  6. use strict;

  7. my $dir = shift || $ENV{'HOME'};
  8. my $total = 0;
  9. my $file;

  10. opendir DIR,$dir;
  11. while ( $file = readdir DIR){
  12.         next if $file eq '.' || $file eq '..';
  13.         $total += 1;
  14. }
  15. print("$total \n");
  16. closedir DIR;

上一篇:管理中心的模版脚本
下一篇:Net::Ping模块实现自己的主机存活检测工具