1.11M Members

Graphical Listing of File and Folders Using Perl

 
0
 

I wanted a graphical representation of the listing of my files and folders from the command line interface, just like what the CLI tree would give on linux system, I really don't like how the same command is displayed on windows.
So, I called on ma 'Cherie' Perl do it for me.
The posted perl script works fine, even on perl version as old as 5.6.0.
Please feel free to use, comment and modify for your own good.
I would also be willing to help in case anyone what explaination or usage on this code.

Thanks for stoping by, checking and using.....

#!/usr/bin/perl -w
use strict;
use File::Find qw(find);
use File::Spec qw(splitdir);

my $depth           = 0;
my $number_of_dir   = 0;
my $number_of_files = 0;

find( \&wanted, shift || '.' );

print sprintf "%d directories, %d files\n", $number_of_dir, $number_of_files;

sub wanted {
    if ( $_ eq '.' || $_ eq '..' ) {
        print $File::Find::name, $/;
        $number_of_dir--;
    }

    if (-d) {
        ++$number_of_dir;
        $depth = scalar File::Spec->splitdir($File::Find::name);
        print "   |" x $depth, '-- ', $_, '/', $/ unless $_ eq '.' or $_ eq '..';
    }
    else {
        ++$number_of_files;
        print "   |" x ( $depth + 1 ), '-- ', $_, $/;
    }
}
Isn't it about time forums rewarded their contributors?

Earn rewards points for helping others. Gain kudos. Cash out. Get better answers yourself.

It's as simple as contributing editorial or replying to discussions labeled or OP Kudos

You
This is an OP Kudos discussion and contributors may be rewarded
Post:
Start New Discussion
View similar articles that have also been tagged: