Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^3: Eliminating Recursive Tree Walking by using MJD-style Infinite Streams?

by Anonymous Monk
on Jun 17, 2008 at 06:12 UTC ( #692438=note: print w/replies, xml ) Need Help??


in reply to Re^2: Eliminating Recursive Tree Walking by using MJD-style Infinite Streams?
in thread Eliminating Recursive Tree Walking by using MJD-style Infinite Streams?

Here is some code I wrote back in 2001 that takes advantage of the fact that we can push onto an array we are currently iterating over. So it's called an infinite stream eh, cute name. Anyway this happily recurses a directory (or any other) tree.

my $root = 'c:/somedir/'; my @dirs = ($root); my @files; for my $path (@dirs){ opendir ( DIR, $path ) or next; # skip dirs we can't read while (my $file = readdir DIR) { next if $file eq '.' or $file eq '..';# skip dot files next if -l $path.$file; # skip sym links if ( -d $path.$file ) { push @dirs, $path.$file.'/'; # add dir to list } else { push @files, $path.$file; # add file to list } } closedir DIR; }
  • Comment on Re^3: Eliminating Recursive Tree Walking by using MJD-style Infinite Streams?
  • Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2021-12-09 13:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    R or B?



    Results (36 votes). Check out past polls.

    Notices?