fork download
  1. #!/usr/bin/perl
  2. use File::Find;
  3. use File::Copy;
  4. use File::Basename;
  5.  
  6. $HOME_dir = `echo \$HOME`;
  7. chomp $HOME_dir; #刪去換行符
  8. $dst_dir = $HOME_dir."/Desktop/tmp/"; #目的路徑
  9. $pic_dir = $HOME_dir."/magic/dir"; #圖片檔目錄
  10. $filename = "list2.txt";
  11. #-- 遞迴找檔案 --
  12. sub find_file {
  13. $dir = $File::Find::dir;
  14. $fname = $File::Find::name;
  15. $name = $_;
  16. $basename = fileparse($fname, qr/\..*/);
  17. next if ($name =~ /^\./);
  18. next if (-d $name);
  19. $num = $basename;
  20. if ($p_num eq $num) {
  21. print "find!!\n";
  22. $newfile = $dst_dir.$name;
  23. print "File: $fname\n";
  24. print "Dst:$newfile\n";
  25. if (-d $dst_dir) {
  26. copy ($fname, $newfile);
  27. } else {
  28. mkdir($dst_dir);
  29. copy ($fname, $newfile);
  30. }
  31. }
  32. } #sub END
  33. #測試tmp目錄是否存在,如果不在就建立目錄
  34. if (!-d $dst_dir) {
  35. mkdir($dst_dir);
  36. }
  37. open FILE, $filename or die "Can't open $filename";
  38. while (<FILE>) {
  39. print "Part:$_\n";
  40. $p_num = $_;
  41. find (\&find_file, $pic_dir); #執行遞迴找圖片檔案
  42. }
  43. $command = "find $pic_dir -type f | wc -l";
  44. $count = `$command`;
  45. print "Total find files:$count\n";
Runtime error #stdin #stdout #stderr 0.02s 7656KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Can't open list2.txt at prog.pl line 37.