Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Full path to files

by gasho (Beadle)
on Apr 11, 2006 at 20:19 UTC ( #542661=perlquestion: print w/replies, xml ) Need Help??

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

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

    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 );
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

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://542661]
Approved by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2023-03-22 02:18 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (60 votes). Check out past polls.