So I added and subtracted a little and came up with a new version. I took most of the sugestions to heart and hopefully made some better code. I also made a couple of changes of my own, such as test for existance first. Also seeing everyone seemed to think that I allowed for files that start with .'s to be seen are sorely mistaken. As per the comments in the code(I tend to use them widely) files that start with .'s are not allowed to be seen and is atomaticly added to the list in the join function later in the script(check it out I speak the tructh). The End!
#!/usr/bin/perl -wT ##################################################### #####Web Site Directory Print ##### #####Copyright 2001, Jonathan Clover ##### ##### ##### #####Description: Program to Print out in plain ##### #####text tab-deliminated representation of a ##### #####directory structure. Has the ability to not##### #####include any directory, as well as allows ##### #####for a specific web directory to be ##### #####specified within the quiry string formated ##### #####like "?dir=/about". ##### ##################################################### use strict; use CGI; $CGI::DISABLE_UPLOADS = 1; $CGI::POST_MAX = 51_200; my ($web_dir, $default_dir, $tab, @non_include); #################### ###Configurations### #################### #Home Web Directory $web_dir = "/www2/nati"; #Default Directory to Start in if you #wish it not to be the Home Web Directory #$default_dir = "/www2/nati"; #Tab String to use for print out $tab = "\&nbsp;\&nbsp;\&nbsp;\&nbsp;"; #Files not to include #Those that start with . are never included #for obvious reasons(aka infinite recursion #and people trying to %#&@ with the script) #Regex accepted as values in list @non_include = ('_', #Front Page Hidden Folders 'Merchant2', #The Online Store Data Folder 'webstats'); #The Web Statstistics Folder ########################### ###End of Configurations### ########################### my $cur = CGI->new(); my $start; my $non_include = '^(\.|'.join('|', @non_include).')'; ###Allow for Param's from a web interface### if ( $cur->param("dir") ){ my ( $temp ) = ( $cur->param("dir") =~ /([\w\/]+)$/ ); $start = $web_dir.$temp; } else { $start = defined($default_dir)? $default_dir : $web_dir; } ###Calculate the number of tabs to be ###used when printing out results my @start = split('/', $start); my $tabs = $#start; ###Start the program and print out as plain text print "Content-Type: text/html\n\n", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Strict//EN\">\n", "<html>\n", "<head>\n", "\t<title>Dir Structure Print</title>\n", "</head>\n", "<body>\n"; dir_tree($start); print "</body>\n</html>"; ###Subrotines Below### sub dir_tree { my ($dir) = @_; my @dir = split('/', $dir); if(-e $dir){ print $tab x ($#dir - $tabs), $dir[$#dir]."<br>\n"; } else { print $dir[$#dir]." does not exist"; } if(-d $dir && !(-l $dir)){ foreach (op_dir($dir)){ dir_tree($_); } } } sub op_dir { my $dir = shift; my @dir; opendir(DIR, $dir) || die "Couldn't open dir: $!"; foreach (sort {lc($a) cmp lc($b)} readdir(DIR)){ if ($_ !~ m/$non_include/){ push(@dir, "$dir\/$_"); } } return @dir; }
Clovs aka jclovs
$_=crypt("hssq","cr");m-[funki.g.jim.bed.wax]-i;$_=eval"$`\(\"czEW\",\ +"pr\"\).$`(\"CCSBD\",\"Cl\")";s+ltO8f+ +;s=kt|g|m.|YA=\"=g;s|[ej]|\"\ +.\"|g;eval;

In reply to One more time by jclovs
in thread Dir Structure Print out by jclovs

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.