0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

perl script works as tree command, recursive call

Posted at

this has been 5 years old, but to keep it.
if any suggestions or security hole, please share them.

tree.pl
# ! /usr/bin/perl

# use strict;
# use warnings;

###########################
# same as Windows NT tree #
###########################

$dir = `pwd`;
print $dir;
$dep = 1;
&dirproc($dep);

sub dirproc {
    # localize values, cz it's recursive sub-routine.
    my($dep) = @_;
    my(@files, $file);

    # get all files in the current directry.
    @files = sort(glob("*"));

    # show all files in the current directry.
    foreach $file (@files){
        if (-f $file){
            for ($i = 1; $i <= $dep; $i++){
                print "|\t";
            }
            print $file."\n";
        }
    }

    # show all directry in the current directry.
    # if directry, calls dirproc again.
    foreach $file (@files){
        if(-d $file){
            for ($i = 1; $i <= $dep; $i++){
                print "|\t";
            }
            print $file."\n";
            ++$dep;
            chdir($file);
            &dirproc($dep);
            chdir("..") or die "abort, maybe your environment is lack of memory.";
            --$dep;
        }
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?