Guest User

Untitled

a guest
Feb 27th, 2020
102
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5. #use Cwd qw(cwd);
  6.  
  7. my $trass=0;
  8. my $dir;
  9. if($#ARGV == 0){
  10. if($ARGV[0] eq '?') {
  11. print "Recursive output\n";
  12. exit;
  13. }
  14. else { $dir = $ARGV[0]; }
  15. }
  16. else {
  17. $dir = $ARGV[0];
  18. $trass=1;
  19. }
  20.  
  21. my @direct = ();
  22. my @files = ();
  23. my $tmp_dir=$dir;
  24. push(@direct, $tmp_dir);
  25.  
  26. while(scalar @direct > 0) {
  27.  
  28. $tmp_dir=shift @direct;
  29.  
  30. if ($trass) {print "tmp_dir is: " . $tmp_dir . "\n";}
  31.  
  32. if($tmp_dir ne " ") {
  33. #print "Zashlo" . "\n";
  34. opendir (DIR, $tmp_dir) or die $!;
  35. }
  36.  
  37. while (my $file_name = readdir(DIR))
  38. {
  39.  
  40. if ($trass) {print "$file_name\n";}
  41.  
  42. if (-f $file_name) {
  43. if ($trass) {print "Ya tut" . "\n";}
  44. my ($ext) = $file_name =~ /(\.[^.]+)$/;
  45. my $foo = reverse($ext);
  46. chop($foo);
  47. $ext = reverse($foo);
  48. my $bool = 1;
  49. foreach my $el (@files) { $bool = 0 if ($el eq $ext); }
  50. if ($bool) { push(@files, $ext); }
  51. }
  52.  
  53. if (-d $file_name) {
  54. if ($trass) {print "future tmp_dir is: " . $file_name . "\n";}
  55. my $bool=$file_name=~s/\./ /g;
  56. if( ($bool eq '') or ($bool =~ /^ *$/) or ($bool =~ /^\s*$/) ) {
  57. #print "file_name: " . $file_name . "\n";
  58. my $tmp_tmp_dir= $tmp_dir . '/' . $file_name;
  59. push(@direct, $tmp_tmp_dir);
  60. }
  61. else {
  62. #print "file_name: " . $file_name . "\n";
  63. my $tmp_tmp_dir= $tmp_dir . '/' . $file_name;
  64. #push(@direct, $tmp_tmp_dir);
  65. }
  66. }
  67.  
  68. }
  69.  
  70. closedir(DIR);
  71.  
  72. }
  73.  
  74. print "Length: " . (scalar @files) . "\n";
  75.  
  76. foreach my $item (@files) {
  77. print $item . "\n";
  78. }
RAW Paste Data