Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

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

by Anonymous Monk
on May 11, 2002 at 01:23 UTC ( [id://165823]=note: print w/replies, xml ) Need Help??


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

hehe, its my coffee brake so i couldnt resist to bake and submit a homegrown.
it aint pretty and the disclaimer took more mork then the code, but hey , i had three more minutes when it wuz finsihed !
yippy! back to work, if ya like going on holidays you need to get a new job folks, computers are sweet.
i'd just wish atari still survived, or amiga, or .. ohwell, *sigh*, ... i hope this helps someone out there :)
if it does, please enjoy but above all:
be nice
.recurser.pl: #!/usr/bin/perl # automagical-develop-and-do-what-you-want # licenced by your monthly # abZurd.org or abZurd-affiliate visit ;) # http://abzurd.com/legal/licence/automagical # easily install by following next three steps # step 1: # make sure you are programming in perl # yes?, ok, place sub in code :] sub recurse { my $dir = shift; my $action = shift; print "this isn't a dir! ($dir)\n" unless (-d $dir); opendir(DIR,$dir); foreach(readdir(DIR)) { if ($_ =~ /^\..?.?$/) { next; } if (-d "$dir/$_") { &recurse("$dir/$_",$action); } else { &$action("$dir/$_"); } } } # onwarths with the fun part # step 2: # create a sub that does something with all those # digital hunks of data (all bought and paid are they?) sub doMeCauseItHurts { printf "%s\n",shift; # ohyeah,ls -R|dir/s functionality ;) } # step 3: # just call it on the dir and pass it a reference to your sub: &recurse($ENV{USERPROFILE},\&doMeCauseItHurts);

Originally posted as a Categorized Answer.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (1)
As of 2024-04-25 04:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found