[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] Listing Folders and Subfolders



Hello, 

 I was asked to provide a directory tree for a website I'm working on, so I
created the following code, which worked. My question of the more
experienced MacPerl programmers: Was there a better/faster way to do this?



#!/usr/bin/perl5

use DirHandle;
use Cwd 'chdir';


$startdir = $ARGV[0]; #drag and drop "root" folder on droplet version.
chdir "$startdir";
&isDir;

sub isDir {
 my ($d) = new DirHandle ":";
 my (@files, $basedir);
 $basedir = $ENV{'PWD'};
 $printline = $basedir;
 $printline =~ s/$startdir/Root_Level/;
 $numtab = $printline =~ tr/:/\//;
 $printline =~ s/(.*)\/([^\/]*)$/\2/;
 print "   \t" x $numtab, "$printline\/\n";

 @files = $d->read;
 for $file (@files) {
   if (-d $file) {
       chdir ":$file";
       &isDir;
       chdir "$basedir";
    }
 }
 $d->close;
}

__END__

===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org