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
|
2000-02-17 02:11:22 -05:00
|
|
|
next if f =~ /\A\.\.?\z/
|
2000-01-04 23:41:21 -05:00
|
|
|
if File::ALT_SEPARATOR and file =~ /^([\/\\]|[A-Za-z]:[\/\\]?)$/ then
|
|
|
|
f = file + f
|
|
|
|
elsif file == "/" then
|
1998-01-16 07:13:05 -05:00
|
|
|
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
|