perl 遍历目录及子目录下的所有文件

#!/usr/bin/perl -w
use File::Basename;
use Data::Dumper;
use File::Find;

my $dir = $ARGV[0] ||= "/" || die $!;
my @files = get_all_files($dir);

sub get_all_files {
    my ($dir) = @_;
    my @Files;
    # Use $File::Find::name instead of $_ to get the paths.
    find(sub { push @Files, $_ }, $dir);
    return @Files
}


sub work{
    # deal with your file
    print "good luck!\n";
}

__END__

你可能感兴趣的:(perl 遍历目录及子目录下的所有文件)