Recursively run another script on every file in a directory structure. I know you can do the same thing with the "find" command, but the arguments required make my head hurt...

Usage:
(first, name it recurse.pl and put it in a directory in your PATH)
recurse.pl /complete/path/to/other/script.pl dirname
or, if you need arguments to your script
recurse.pl "/complete/path/to/other/script.pl -blah" dirname
might work (amazing that I haven't tested that).

Assumption:
The other script returns a 0 if it succeeds and something else if it fails.
#!/usr/bin/perl #this needs some comments... chdir $ARGV[1]; @ls_retval = `ls -l`; shift ( @ls_retval ); foreach $line (@ls_retval) { @items = split( /\s+/, $line ); $first_char = substr( $items[0], 0, 1 ); if ( $first_char eq 'd' ) { print "directory: $items[8]\n"; print `$0 $ARGV[0] $items[8]`; } elsif ( $first_char eq 'l' ) { print "link: $items[8]\n"; print `$0 $ARGV[0] $items[8]`; } elsif ( $first_char eq '-' ) { print "file: $items[8]\n"; $action_retval = `$ARGV[0] $items[8]`; if ( $action_retval != 0 ) { print "Error $action_retval in $items[8]\n"; } else { print "OK $action_retval for $items[8]\n"; } } } print "Finished\n";

In reply to Recursively run another script by bean

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.