Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Click here to return to the 'Display a tree-like structural view of any directory' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Display a tree-like structural view of any directory
Authored by: clops on Feb 15, '06 07:44:27AM

OR just add an alias to your .bash_profile file, something like

alias dir="ls -R | grep ":" | sed -e 's/://' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'"

[ Reply to This | # ]
With Perl
Authored by: galaher on Feb 15, '06 08:32:15AM
This should run as is. If you have the screen real-estate this is a fun way to look at your Mac. I only added a few lines of this code to call the user. You could modify this to take a direcory as an argument from the terminal or from applescript etc. I changed this to my Documents folder and ran this in BBEdit. It's was blazing fast. In about 7 seconds I got 65,000 lines and with my Mighty Mouse I could easily scroll all over this large page.
#!/usr/bin/perl -w
use strict;
use Data::Dumper;
chomp (my $username = `whoami`);
my $base_path = "/Users/$username/Desktop";
print Dumper(&data_for_path($base_path));
sub data_for_path(){
    my $path = shift;
    if(-f $path or -l $path){ # files or symoblic links
        return undef;
    if(-d $path){
        my %directory;
        opendir PATH, $path or die "Cannot opendir $path: $!";
        my @names = readdir PATH;
        closedir PATH;
        for my $name (@names){
        next if $name eq "." or $name eq "..";
        $directory{$name} = &data_for_path("$path/$name");
        return \%directory;
    warn "$path is neither a file nor a directory\n";
    return undef;

[ Reply to This | # ]