Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- my @list = ();
- ## Sub for parsing new directories after first run
- sub parse_dir {
- opendir(DIR, @_) or die ("Cannot open @_\n");
- my @new_list = map { "@_$_" } readdir DIR;
- push @list, @new_list;
- closedir(DIR);
- }
- ##Check the cmd-line args to make sure only 1 is given
- ##check for directory later on when trying to open
- if(scalar(@ARGV) != 1){
- die("USAGE: ./dumbtree.pl DIRECTORY\n");
- }
- ##set the dir to arg0 and then try to open it
- my $dir = $ARGV[0];
- opendir(DIR, $dir) or die ("Cannot open\n");
- ##save the dir listing to a file
- @list = map { "$dir$_" } readdir DIR;
- closedir(DIR);
- ##for each item in the array, print out some info.
- ##if the item is a readable directory, parse it with sub parse_dir
- ##and have that add it to the end of the array being printed.
- foreach my $item (@list) {
- if(-d $item && -r $item) {
- print $item . "\n";
- if ($item =~ m/[^\.]|[^\.\.]/) {
- parse_dir($item);
- }
- ##Open the directory and put it's contents into @list!
- #opendir(DIR, $item) or die("Cannot open $item\n");
- #my @tmp_list = map{ "$item$_" } readdir DIR;
- #push @list, @tmp_list;
- #closedir(DIR);
- } elsif (-d $item){
- print "Cannot open directory: $item\n";
- }
- if(-f $item && -r $item && -w $item & -x $item) {
- print "Permissions for $item: rwx\n";
- } elsif (-f $item && -r $item && -w $item) {
- print "Permissions for $item: rw-\n";
- } elsif (-f $item && -r $item) {
- print "Permissions for $item: r--\n";
- } else {
- print "Permissions for $item: ---\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement