http://qs1969.pair.com?node_id=542661

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

I was just wandering if there is a Perl module that will return full path to file. For example : I am looking for all *.xml files under C:\test and I will get @Result something like: C:\test\a.xml C:\test\t1\b.xml C:\test\t2\c.xml etc

Replies are listed 'Best First'.
Re: Full path to files
by eff_i_g (Curate) on Apr 11, 2006 at 20:30 UTC
    gasho,

    You could do this by creating a routine that is used with File::Find.

    Untested:
    use File::Find; my @files; sub find_process { push @files, $File::Find::name if /\.xml$/; } find(\&find_process, 'C:/test'); ### Note: I'm not familiar with Windo +ws pathing.
Re: Full path to files
by davidrw (Prior) on Apr 11, 2006 at 21:59 UTC
    a File::Find::Rule example:
    use File::Find::Rule; my @files = File::Find::Rule->file()->name('*.xml')->in("C:\\test");
Re: Full path to files
by wazoox (Prior) on Apr 11, 2006 at 20:31 UTC
Re: Full path to files
by borisz (Canon) on Apr 11, 2006 at 20:32 UTC
    use Data::Dumper; use File::Find qw/find/; my $dir = 'c:/test'; my @res; find( { wanted => sub { -f and /\.xml$/ and push @res, $File::Find::na +me }, follow => 1 }, $dir ); print Dumper( \@res );
    Boris
Re: Full path to files
by GrandFather (Saint) on Apr 11, 2006 at 20:30 UTC

    If what you want to do is further process the files, and especially if you want to find all matching files in a directory tree, then take a look at File::Find


    DWIM is Perl's answer to Gödel