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

dear monks i tried to get all the files with .fmb extension in directory ... using this code but unfortunately it returned only one file i have two files in it can any one help me on this issue. thanks for your help
use File::Spec; my $directory = 'C:\orant\FORMS60\forms\Fapidk\source\msvc\changecolor +\Debug\forms'; $path = File::Spec->catfile( @directories, "*.fmb" ); @files = glob($path);foreach(@files){print "$_\n"; }

Replies are listed 'Best First'.
Re: How to get list of files with .fmb extension in windows
by chromatic (Archbishop) on May 11, 2007 at 18:51 UTC

    Does it work better if you change the third line to:

    $path = File::Spec->catfile( $directory, "*.fmb" );

    Without seeing where you declare @directories, it's difficult to debug the code.

Re: How to get list of files with .fmb extension in windows
by thezip (Vicar) on May 11, 2007 at 18:58 UTC

    Without using File::Spec, you could do (replacing the values as needed):

    #!/perl/bin/perl -w use strict; use Data::Dumper; my $dir = 'C:/WINNT'; my $searchext = 'dll'; opendir(DIR, $dir) || die qq(Could not open directory "$dir"\n); my @files = grep { /\.${searchext}$/ } readdir(DIR); print Dumper(\@files);

    Update:  If you need to check for these files also in the subdirectories (or multiple other directories), my knee-jerk reaction is to use File::Find, which works very well for that purpose.


    Where do you want *them* to go today?
Re: How to get list of files with .fmb extension in windows
by FunkyMonk (Bishop) on May 11, 2007 at 21:29 UTC
    my @files = </path/to/files/*.fmb>;

    works fine on Linux and I don't see why it shouldn't be OK on windows too.