This should be enough to get you started. Caveats: . and .. are not real directories, but are used by the system. Also, if you make these clickable, you shouldn't allow the user to back up past the root directory (basedir, which you should change to suit your system) by feeding req_dir with too many ..s.

Other recommendations: For getting this into a web-based form, you'd want to make the directories clickable, by printing HTML <A> tags around the directories, and then feed the results back to your script with CGI variables. As it is right now, the script below is less useful than the DOS dir command.

my $basedir = '/usr/data/www/you'; ## This is the directory to start +with. my $req_dir = ''; ## This is the subdirectory you want, relative to $ +basedir opendir(DIR, "$basedir/$req_dir") || die "can't opendir $req_dir: $!"; @dir_records = readdir(DIR); @dir_records = sort @dir_records; closedir DIR; $file_count = 0; @dir_dirs = grep {-d "$basedir/$req_dir/$_"} @dir_records; # this stuf +fs @dir_dirs with the directories foreach $thisdir (@dir_dirs) { print "$thisdir (directory)\n"; } foreach $_ (@dir_records) { if (-f "$basedir/$req_dir/$_") { print "$_\n"; } }

andre germain
"Wherever you go, there you are."


In reply to Re: Directory Display and File Print out by Agermain
in thread Directory Display and File Print out by LostS

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.