Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: list of files in subdirectories

by Anonymous Monk
on Jun 06, 2012 at 11:53 UTC ( [id://974704]=note: print w/replies, xml ) Need Help??


in reply to list of files in subdirectories

use File::Find::Rule, see example at Re^2: read the whole folder files (don't specify maxdepth)

Replies are listed 'Best First'.
Re^2: list of files in subdirectories
by Anonymous Monk on Jun 06, 2012 at 14:56 UTC

    Here is a nice example from the book Higher-Order Perl by Mark Jason Dominus

    This example is for win32, but it is easily changable:

    use strict; use warnings; use Time::HiRes qw(gettimeofday tv_interval); my $start_time = [gettimeofday]; my $inp_dir = 'c:\temp\Tmp_User'; my ( $startdir ) = @ARGV; $startdir = $inp_dir; ( defined $startdir ) || usage(); walk_path( \&is_req_file, $startdir ); my $elapsed = tv_interval($start_time); $elapsed = sprintf "%.04f", $elapsed; print "\n...Elapsed is $elapsed sec\n"; 1; sub is_req_file { my ($filn) = @_; print "$filn\n"; return 1; } sub walk_path { my ( $filefunc, $startdir ) = @_; my $dos_cmd = "dir $startdir /b /S /A:-D"; map { $filefunc->($_) } ( split /\n/, qx{$dos_cmd} ); return; }

    The advantage is, that it runs really fast on windows.

    The missing sub usage is left as an exercise.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://974704]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-23 22:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found