in reply to usage of find::file and glob to filter out directories and retrieve selected files

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

  • Comment on Re: usage of find::file and glob to filter out directories and retrieve selected files
  • Select or Download Code