Now, I know this question is kind of taken care of in the Q&A section (which is where I got the idea). However, I wanted to take the recursive listing of directories a little further, and look at using opendir, readdir, and for / map to find and delete contraband (e.g., .mp3 and .exe).

Of course, we all know that filename extensions can be changed, but that's not important as getting the basics down (for example, checking the last 128 bytes in a file for ID3 tags can help to identify an mp3). Here is my codebase (which needs some advising):
#!/usr/bin/perl -w recurse('c:'); #testing this on a windows machine sub recurse { my $dir = shift; #print $dir,$/; opendir(R,$dir) || die $!; my @dives = grep { $_ ne '.' && $_ ne '..' && -d $_ } readdir(R); +#build a list all of the directories @dives = map { join('/',$dir,$_) } @dives; print "$_\n" for @dives; my @contra_band = ('avi','mp3','mp2','mpeg'); my @found; foreach my $a (@contra_band) { my @del = grep { $_ =~ /\Q$a\E$/ } readdir(R); #look for the f +ile extensions map { push(@found,$_) } @del; #create an array of things to un +link later print @del; } map { recurse($_) } @dives; #couldn't think of a for loop to do the + same thing... I don't know what is wrong with me today. }
The only problem with this code, is that it only seems to work on some directories and not others... Any further guidance is appreciated.

Theodore Charles III
Network Administrator
Los Angeles Senior High
4650 W. Olympic Blvd.
Los Angeles, CA 90019
323-937-3210 ext. 224
email->secon_kun@hotmail.com
perl -e "map{print++$_}split//,Mdbnr;"

In reply to Recursing subdirectories for contraband... by Necos

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.