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

With Perl | 33 comments | Create New Account
Click here to return to the 'With Perl' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
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 | # ]