in reply to readdir

Other people have suggested various ways of GLOBbing. Here's a trick for when you want to do the same thing for the exact directory tree. (Using DOSGLOB because c:/temp/ - regular GLOB should also work). The Regex used for the compare uses the greediness thing to match everything up to the last / in the .*

use File::DosGlob; $fn = 'c:/temp/*'; my @m = File::DosGlob::doglob(1,$fn); for (@m) { push @m, $_.'/*' if -d($_); # if directory add contents to end of Arra +y if (m!^.*/xxxx!) { # if filename starts with xxxx do_something_with($_); } }
Share and Enjoy
Dingus

Replies are listed 'Best First'.
Re: Re: readdir
by dingus (Friar) on Oct 30, 2002 at 13:46 UTC
    sorry cut and pasted the broken script. This is better
    use File::DosGlob; $fn = 'c:/temp/*'; my @m = File::DosGlob::doglob(1,$fn); for (@m) { # if directory add contents to end of Array push @m, File::DosGlob::doglob(1,$_.'/*') if -d($_); if (m!^.*/xxxx!) { # if filename starts with xxxx do_something_with($_); } }