My requirement is to find certain files with same extension(e.g .pl) that might be present in different directories. So I want to filter out the directories based on the presence of the files that i'm searching for.

Are you looking for files or directories? If you find the files you're looking for, there is no need to do any kind of filtering of directories

Shell commands

md tmp3 md tmp3\a md tmp3\a\a md tmp3\a\b md tmp3\a\c md tmp3\a\d md tmp3\b\a md tmp3\b\b touch tmp3\a\b\f.pl touch tmp3\a\c\f.pl touch tmp3\b\b\f.pl findrule tmp3 -file ( *.pl ) perl -MFile::Find::Rule -le " print for File::Find::Rule-> file( q(*.p +l) )->in( q(tmp3) ); " perl -MFile::Glob=:glob -le " while(@ARGV){ print for glob shift } " " +tmp3/*pl" "tmp3/*/*pl" "tmp3/*/*/*pl"
Shell session
$ md tmp3 $ md tmp3\a $ md tmp3\a\a $ md tmp3\a\b $ md tmp3\a\c $ md tmp3\a\d $ md tmp3\b\a $ md tmp3\b\b $ touch tmp3\a\b\f.pl $ touch tmp3\a\c\f.pl $ touch tmp3\b\b\f.pl $ findrule tmp3 -file ( *.pl ) tmp3/a/b/f.pl tmp3/a/c/f.pl tmp3/b/b/f.pl $ perl -MFile::Find::Rule -le " print for File::Find::Rule-> file( q(* +.pl) )->in( q(tmp3) ); " tmp3/a/b/f.pl tmp3/a/c/f.pl tmp3/b/b/f.pl $ perl -MFile::Glob=:glob -le " while(@ARGV){ print for glob shift } " + "tmp3/*pl" "tmp3/*/*pl" "tmp3/*/*/*pl" tmp3/a/b/f.pl tmp3/a/c/f.pl tmp3/b/b/f.pl
I quoted "tmp3/*/*/*pl" because bash/csh/sh... will glob for you (cmd.exe doesn't).

findrule, File::Find::Rule, File::Glob


In reply to Re: usage of find::file and glob to filter out directories and retrieve selected files by Anonymous Monk
in thread usage of find::file and glob to filter out directories and retrieve selected files by archer

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.