perl 文件遍历

2136阅读 1评论2011-01-05 heut2009
分类:

#!/usr/bin/perl
use strict;
my $dir = $ARGV[0];

&fun ($dir);

sub
fun ()
{
  my $current = shift;
  opendir DIR, $current or die "can not open dir";
  my @ list = readdir DIR;
  foreach my $item (@list)
  {
    if (-f $current."/".$item)
      {
        print $item." is a file\n";
      }
    else
      {
        if (-d $current."/".$item && $item ! ~/^[\.]{1, 2}/)
          {
            print $item." is a directory\n";
            &fun ($current."/".$item);
          }

      }
  }
}

上一篇:系统 缓冲
下一篇:没有了

文章评论