Advertisement
Guest User

Untitled

a guest
May 22nd, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.55 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. my @list = ();
  7.  
  8. ## Sub for parsing new directories after first run
  9. sub parse_dir {
  10.     opendir(DIR, @_) or die ("Cannot open @_\n");
  11.  
  12.     my @new_list = map { "@_$_" } readdir DIR;
  13.     push @list, @new_list;
  14.  
  15.     closedir(DIR);
  16. }
  17.  
  18. ##Check the cmd-line args to make sure only 1 is given
  19. ##check for directory later on when trying to open
  20. if(scalar(@ARGV) != 1){
  21.     die("USAGE: ./dumbtree.pl DIRECTORY\n");
  22. }
  23. ##set the dir to arg0 and then try to open it
  24. my $dir = $ARGV[0];
  25. opendir(DIR, $dir) or die ("Cannot open\n");
  26. ##save the dir listing to a file
  27. @list = map { "$dir$_" } readdir DIR;
  28. closedir(DIR);
  29.  
  30. ##for each item in the array, print out some info.
  31. ##if the item is a readable directory, parse it with sub parse_dir
  32. ##and have that add it to the end of the array being printed.
  33. foreach my $item (@list) {
  34.     if(-d $item && -r $item) {
  35.         print $item . "\n";
  36.         if ($item =~ m/[^\.]|[^\.\.]/) {
  37.             parse_dir($item);
  38.         }
  39.         ##Open the directory and put it's contents into @list!
  40.         #opendir(DIR, $item) or die("Cannot open $item\n");
  41.         #my @tmp_list = map{ "$item$_" } readdir DIR;
  42.         #push @list, @tmp_list;
  43.         #closedir(DIR);
  44.  
  45.     } elsif (-d $item){
  46.         print "Cannot open directory: $item\n";
  47.     }
  48.  
  49.     if(-f $item && -r $item && -w $item & -x $item) {
  50.         print "Permissions for $item: rwx\n";
  51.     } elsif (-f $item && -r $item && -w $item) {
  52.         print "Permissions for $item: rw-\n";
  53.     } elsif (-f $item && -r $item) {
  54.         print "Permissions for $item: r--\n";
  55.     } else {
  56.         print "Permissions for $item: ---\n";
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement