regex - List files that exist only on a given directory? -
i trying list out files in directory ./a/b
or ./a/d
. explicitly specifying using (-d && $_ =~ "b") || (-d && $_ =~ "d")
. there way can put needed folders in array?
use file::find; $filename = "h*.txt"; print ("now it's:", $filename); find({ wanted => \&wanted, preprocess => \&dir_preprocess, }, './a'); sub dir_preprocess { (@entries) = @_; #my @tmparr=("d","b"); isn't working if ( $file::find::dir eq './a' ) { @entries = grep { (-d && $_ =~ "b") || (-d && $_ =~ "d") }@entries; } return @entries; } @mylist; sub wanted{ if($_ =~ $filename) { push(@mylist, $_); } } print ("it's:", @mylist);
you can use |
"or" in regex expression. (-d && $_ =~ /(b|d)/)
match either b or d. put names in array , use join
generate regex need.
you might want things prepend path upto depth, else might @ different levels of heirarchy. can add $
@ end indicate comes @ end.
Comments
Post a Comment