I had so much fun doing that that I did one that did a little more :
Try this it's a little creamier since it uses <UL> tags instead of •
And it lists files in the directories that are in the directory in $dir ::
I better stop now or I'll be messing with this all night!
!#/usr/bin/perl
use warnings;
use strict;
use CGI qw/:standard/;
use File::Slurp;
my $dir = '.'; # hardcoded, from input $dir = param('dir'), from function like cwd(),
etc...
print header();
my @files = read_dir($dir);
print "<P> <UL> \n";
foreach my $f(@files) {
if(-d "$dir/$f") {
print "<LI> <a href=\"$f\"> $f </a> \n";
print "<UL>\n";
my @tmp = read_dir("$dir/$f");
foreach my $s(@tmp) {
print "<LI> <a href=\"$f/$s\"> $f/$s </a>\n";
}
print "</UL>\n";
} else {
print "<LI> <a href=\"$f\"> $f </a>\n";
}
}
print "</UL> <P>\n";
> Thanks for your help! You saved me a lot of mis-programming.
> Yea, I'm really interested in the new challenges -- I just
> wish I already knew perl. It can do so much.
>
> --Deb
>
> -----Original Message-----
> From: Dan Muey [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, March 05, 2003 3:02 PM
> To: Scott, Deborah; [EMAIL PROTECTED]
> Subject: RE: How to look into every subdirectory
>
>
> > I need to make an HTML page that lists all files and
> > directories and then links to them. The following script,
> > with a subroutine, looks like what I need. I should just
> > need to add some html tags to the Print statements.
> >
> > Does that sound right to you all? Or do you have better
> > suggestions? (I'm a real beginner at Perl, but my job has
> > suddenly starting requiring lots of perl scripts!)
> Sounds like a cool job!
>
> Here's what I'd do to get a list of links to all the
> files and directories and make an html page out of it ::
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
> use CGI qw/:standard/;
> use File::Slurp;
>
> my $dir = '.'; # hardcoded, from input, from function like
> cwd(), etc...
>
> print header();
>
> my @files = read_dir($dir);
>
> foreach my $f(@files) { print "\&\#149\; <a href=\"$f\"> $f
> </a> <br> \n"; }
>
>
> Then from there you can get fancy like checking for the file type and
> displaying different icons for each one,
> Having alist of files/types to not display links to, taking
> directories and
> making a list of files with links in each of them also, and on and on.
> You could also add a header and footer tyo make it look ike
> the rest of your
> site
>
> Perl is awesome!!
>
> Learn how to use modules, it's tricky at first but you'll
> save yourself lots
> of time.
>
> DMuey
>
> >
> > --Deborah
> > (I asked this question a while back, but my email messages
> > got messed up and I can't find the answer that I got.)
> >
> > -----Original Message-----
> > From: Beau E. Cox [mailto:[EMAIL PROTECTED]
> > Sent: Tuesday, February 25, 2003 12:29 PM
> > To: Prasad Karpur; [EMAIL PROTECTED]
> > Subject: RE: How to look into every subdirectory
> >
> >
> > Hi -
> >
> > > -----Original Message-----
> > > From: Prasad Karpur [mailto:[EMAIL PROTECTED]
> > > Sent: Tuesday, February 25, 2003 3:18 AM
> > > To: [EMAIL PROTECTED]
> > > Subject: How to look into every subdirectory
> > >
> > >
> > > I am new to Perl and would like to know how to look into every
> > > subdirectory. Any help would be greatly appreciated.
> > >
> > > #!/usr/bin/perl
> > >
> > > #use strict;
> > > use Cwd;
> > >
> > > my $curr = cwd();
> > > opendir(CURRDIR, $curr) or die "can't open directory ($!),
> > > exiting.\n";
> > >
> > > my @files = readdir(CURRDIR);
> > > #closedir(CURRDIR);
> > >
> > > foreach my $file (sort @files) {
> > >
> > > next if $file eq '.' || $file eq '..';
> > > next if !-d $file;
> > >
> > > if (-d $file) {
> > > print "$file/\n"; #Puts a slash in front of every directory
> > > it encounters
> > > }
> > > else { print "$file\n"; }
> > >
> > > }
> > >
> > >
> > > closedir(CURDIR);
> > >
> >
> > Just use a recursive subroutine to traverse your directory
> > tree from any starting point:
> >
> > traverse (cwd());
> >
> > sub traverse
> > {
> > my $dir = shift;
> > $dir .= '/' unless $dir =~ m{/$};
> > opendir (DIR, $dir) ||
> > die "unable to open directory $dir: $!\n";
> > my @contents = readdir (DIR);
> > closedir (DIR);
> >
> > for my $item (sort @contents) {
> > my $di = "$dir$item";
> > next unless (-d $di);
> > next if ($item eq '.' or $item eq '..');
> > print "dir: $di\n";
> > traverse ($di);
> > }
> >
> > for my $item (sort @contents) {
> > my $di = "$dir$item";
> > next if (-d $di);
> > print "file: $di\n";
> > }
> > }
> >
> > Try the above; WARNING: may contain typos! :)
> >
> > Also - check out File::Find on CPAN.
> >
> > Aloha => Beau;
> >
> >
> > --
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> > --
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]