perlprint has asked for the wisdom of the Perl Monks concerning the following question:

can I transeverse thru a directory using a regex as input instead of absolte path of dir.Say if i give input as D"//Settings//* ..it shld display alll files inside each dir and sub dir of settings....if i gived://settings//*.zip den shld display all files inisde all dir and sub dir of settings that have .zip extension...

  • Comment on Transversing thru dir using regex rather than a absolute path

Replies are listed 'Best First'.
Re: Transversing thru dir using regex rather than a absolute path
by Corion (Patriarch) on Apr 12, 2010 at 09:20 UTC

    What code have you already written and where do you encounter problems?

    You might want to read File::Find.

Re: Transversing thru dir using regex rather than a absolute path
by cdarke (Prior) on Apr 12, 2010 at 09:49 UTC
    You are probably thinking of glob constructs, which are different to regular expressions. In your example D:/Settings/* (not sure why you used //), "*" in globbing means a filename consisting of "zero or more of any valid character", whereas in a regular expression that would be ".*". The "*" is a quantifier, it quantifies the character, or group of characters, to its left. The dot "." in regular expressions mean one single character, whereas in globbing that would be "?".

      $val="D:\\VmWare\\*"; find(\&print_name, "$val"); sub print_name { push(@array_name,$File::Find::name); } foreach $val(@array_name) { print "$val \n"; }

      actually i have more paths where u have * in middle of the path also.The output of above is giving as empty

Re: Transversing thru dir using regex rather than a absolute path
by Anonymous Monk on Apr 12, 2010 at 09:22 UTC