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

Re: How do I recursively process every file in a given directory?

by marcos (Scribe)
on May 02, 2000 at 14:15 UTC ( [id://9920]=note: print w/replies, xml ) Need Help??


in reply to How do I recursively process every file in a given directory?

I would use opendir and readdir:
opendir (DIR, $dir) or die "cannot opendir $dir"; foreach my $file (readdir(DIR)) { &process_file ($file); } closedir (DIR);

or to process ONLY files:
my @only_files = grep {-f "$dir/$_"} readdir(DIR); foreach my $file (@only_files) { &process_file ($file); }

and finally a one-line-do-everything version (my favorite one):
map {&process_file} grep {-f "$dir/$_"} readdir(DIR);

marcos

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2024-03-28 21:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found