Submitted by anonymous (Thu Aug 21 14:08:47 UTC 2003)
So, given a directory setup like
/dir / subdir subdir2 /
subsub subsub2
Doing
Dir.recurse(".") { |d| puts d}
Would print
/dir /dir/subdir /dir/subdir2 /dir/subdir/subsub /dir/subdir/subsub2
With a maxdepth argument,
Dir.recurse("/dir", 1) {|d| puts d}
would print
/dir /dir/subdir /dir/subdir2
Comments | Current voting | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
RCRchive copyright © David Alan Black, 2003-2005.
Powered by .
Probably not needed (, 2003-08-25 06:41:06)
The only major differences are that Find.find "finds" everything, not just directories, and doesn't have an argument to specify the max depth to which to recurse. The first is probably not an issue at all, because you would normally be more interested in the files within directories than in the directories themselves. In case it's the directories that are interesting, it's easy enough to insert a "next unless FileTest.directory? f" or the like in the block. The "max depth" argument could still be useful, I think, but it can likewise be pretty easily implemented within the block passed to Find.find.
In any case, I don't think this RCR has any merit as-is, because the proper place to implement anything extra would be within Find.find, of which I was not originally aware.
Dir can do something like that... (flori, 2003-09-08 06:34:31)
Dir["/etc/**/*"].each do |x| puts x end
lists all files in /etc and its recursive sub directories.