Created
November 28, 2012 17:41
-
-
Save fser/4162780 to your computer and use it in GitHub Desktop.
Displays directory tree easy way with only printable characters (unlike gnu tree)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# François Serman <[email protected]> | |
# 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