CHRYSt, you'll find many posts here directing you to File::Find. It's very easy to use (although there are some peculiarities that may put you off at first, much clearer code can be produced with it than you'll find in my sample below)

Download the snippet below, and see if it does pretty much what you want. I can hardly imagine it taking 3 hours, even on a very large and deep directory.

If it works for you, take a closer look at the module and the examples in the documentation (perldoc File::Find).

#!/usr/bin/perl -w use strict; use File::Find; print "Content-Type: text/html\n\n"; print "<html><body><h1>Web Server Directory Listing</h1>"; my $dir_count = 0; my $file_count= 0; find(\&{ sub { if (-d $_){ # File::Find puts us in the directory. # We can stat, copy or rename # without needing to know # which directory we are in. print $dir_count > 0?"</ul>\n":""; print "<h3>Directory ", ++$dir_count, ": <a href='$File::Find::dir/$_'>$_</a></h3>\n<ul> \ +n" ; # $File::Find::dir # is the current directory } else{ print "<li>", ++$file_count, " <a href='$File::Find::name'>$_</a></li>\n" ; # $File::Find::name # is the full path of the c +urrent file. } } }, '/Intranet/html'); print "\n</ul>"; print "</body></html>";

mkmcconn
fiddled with text after posting.


In reply to Re: recurse directory script by mkmcconn
in thread recurse directory script by CHRYSt

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.