I return with another question that those skilled in the art might kindly help me with...

I want to recursively scan all the directories and subdirectories from a given starting point. At some point in the future I'm going to do things to the security on all files in the directory - the reason I'm using Perl is that (a) DOS batch is rubbish and (b) CACLS.EXE is rubbish and (C) I need to look at the security before doing the aforementioned things.

But enough natter; here's the subroutine that, at the moment, is intended to print out a recursive listing of the directory tree:

sub printdir { my $item; foreach $item(@_) { if (-d $item) { print "$item\n"; opendir(SUBDIR, $item) or croak "Can't open directory :$!"; my @subdir_items = readdir(SUBDIR); #+ closedir(SUBDIR); #+ printdir(@subdir_items); #+ } } }
At the moment, it simply prints out the very first eligible item, lots of times, with the odd warning about deep recursion.

This nicely printed out the items in a single directory before I added the lines marked with #+.


In reply to Recursive directory scanning by pwhysall

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.