> 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]

Reply via email to