find(*paths)
private
Calls the associated block with the name of every file and directory listed
as arguments, then recursively on their subdirectories, and so on.
See the Find module documentation for an
example.
Show source
def find(*paths)
block_given? or return enum_for(__method__, *paths)
paths.collect!{|d| raise Errno::ENOENT unless File.exist?(d); d.dup}
while file = paths.shift
catch(:prune) do
yield file.dup.taint
begin
s = File.lstat(file)
rescue Errno::ENOENT, Errno::EACCES, Errno::ENOTDIR, Errno::ELOOP, Errno::ENAMETOOLONG
next
end
if s.directory? then
begin
fs = Dir.entries(file)
rescue Errno::ENOENT, Errno::EACCES, Errno::ENOTDIR, Errno::ELOOP, Errno::ENAMETOOLONG
next
end
fs.sort!
fs.reverse_each {|f|
next if f == "." or f == ".."
f = File.join(file, f)
paths.unshift f.untaint
}
end
end
end
end