use strict; use Cwd; sub get_dir_file { my $path = shift @_; # print $path; opendir(TEMP,$path) || die "open $path fail...$!"; my @FILES = readdir TEMP; for my $filename (@FILES) { if ($filename eq "Thumbs.db" || $filename eq "." || $filename eq ".." || $filename eq ".svn" || $filename eq "get_file_list.pl") { } else { if (-d "$path/$filename") { #print "$path/$filename"."\n"; get_dir_file("$path/$filename"); } else { write_to_file("$path/$filename"); } } } closedir(TEMP); } sub write_to_file { my $text = shift @_; open(STOREFILE,">>file_list.txt"); print "$text\n"; syswrite(STOREFILE,"$text\r\n"); close(STOREFILE); } unlink "file_list.txt"; my $curDir = getcwd; get_dir_file($curDir);
遍历目录并打印目录下所有文件名
my $curDir = getcwd;获取当前目录