【perl】遍历当前目录下所有文件
1 #!/usr/bin/perl 2 use strict; 3 use Getopt::Long; 4 5 my $dir_path; 6 my $file_output; 7 8 GetOptions( 9 'dir_path|dir=s'=>\$dir_path, 10 'file_output|fo=s'=>\$file_output, 11 ); 12 13 open FILE, ">", $file_output; 14 print "all files under $dir_path are listing!\n"; 15 &list($dir_path); 16 print "all files under $dir_path are listed!\n"; 17 18 if(!(-e "./script_gen" && -d "./script_gen")) { 19 `mkdir script_gen`; 20 `mv $file_output script_gen`; 21 } 22 else { 23 `mv $file_output script_gen`; 24 } 25 26 sub list{ 27 my $file=shift @_; 28 if(-d $file) { 29 &list($_) foreach <$file/*>; 30 } 31 else { 32 print FILE "$file\n"; 33 } 34 } 35 36 close FILE;