Update: See ikegami's reply for a working solution :)

Here is one way to get just the subdirectories of the current directory (using File::Slurp, grep and -d), then run your command in each dir (using chdir and system):

use strict; use warnings; use File::Slurp qw(read_dir); my @dirs = grep { -d } read_dir('./'); for (@dirs) { chdir $_; system '/somepath/foo.exe'; }

If you want to run it in all directories recursively, then find or File::Find would be appropriate.

You should be specific about the problem you are having. Why doesn't it work for you?

You should choose a more meaningful title for your question, like: "Problem running command in subdirectories.".


In reply to Re: trouble with a simple script by toolic
in thread problem running executable in subdirectories by apollo

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.