1998-01-16 07:13:05 -05:00
|
|
|
# Usage:
|
1999-01-19 23:59:39 -05:00
|
|
|
# require "find"
|
1998-01-16 07:13:05 -05:00
|
|
|
#
|
|
|
|
# Find.find('/foo','/bar') {|f| ...}
|
|
|
|
# or
|
|
|
|
# include Find
|
|
|
|
# find('/foo','/bar') {|f| ...}
|
|
|
|
#
|
|
|
|
|
|
|
|
module Find
|
|
|
|
def find(*path)
|
|
|
|
while file = path.shift
|
|
|
|
catch(:prune) {
|
|
|
|
yield file
|
1999-01-19 23:59:39 -05:00
|
|
|
if File.directory? file then
|
1998-01-16 07:13:05 -05:00
|
|
|
d = Dir.open(file)
|
|
|
|
begin
|
|
|
|
for f in d
|
|
|
|
next if f =~ /^\.\.?$/
|
|
|
|
if file == "/" then
|
|
|
|
f = "/" + f
|
|
|
|
else
|
|
|
|
f = file + "/" + f
|
|
|
|
end
|
|
|
|
path.unshift f
|
|
|
|
end
|
|
|
|
ensure
|
|
|
|
d.close
|
|
|
|
end
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def prune
|
|
|
|
throw :prune
|
|
|
|
end
|
|
|
|
module_function :find, :prune
|
|
|
|
end
|