Skip to content

Instantly share code, notes, and snippets.

@fser
Created November 28, 2012 17:41
Show Gist options
  • Save fser/4162780 to your computer and use it in GitHub Desktop.
Save fser/4162780 to your computer and use it in GitHub Desktop.
Displays directory tree easy way with only printable characters (unlike gnu tree)
#!/usr/bin/perl
# François Serman <aifsair@gmail.com>
# 07 nov 2012
#
# Displays a treeview of a directory, very simply.
# If no parameters is given, takes PWD as base.
use strict;
our $prefix = shift || $ENV{PWD};
sub tree
{
my ($base, $offset) = @_;
foreach (<$base/*>) {
my $file = $_;
$file =~ s/$prefix\///;
print '|';
print '_' x $offset . ' ';
print $file . (-d $_ ? '/' : '') . "\n";
tree ($_, $offset+1) if (-d);
}
}
print "$prefix/\n";
tree $prefix, 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment