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
|
2000-10-02 03:48:42 -04:00
|
|
|
catch(:prune) do
|
1998-01-16 07:13:05 -05:00
|
|
|
yield file
|
2000-10-02 03:48:42 -04:00
|
|
|
begin
|
|
|
|
if File.lstat(file).directory? then
|
|
|
|
d = Dir.open(file)
|
|
|
|
begin
|
|
|
|
for f in d
|
|
|
|
next if f == "." or f == ".."
|
|
|
|
if File::ALT_SEPARATOR and file =~ /^(?:[\/\\]|[A-Za-z]:[\/\\]?)$/ then
|
|
|
|
f = file + f
|
|
|
|
elsif file == "/" then
|
|
|
|
f = "/" + f
|
|
|
|
else
|
|
|
|
f = File.join(file, f)
|
|
|
|
end
|
|
|
|
path.unshift f
|
1998-01-16 07:13:05 -05:00
|
|
|
end
|
2000-10-02 03:48:42 -04:00
|
|
|
ensure
|
|
|
|
d.close
|
1998-01-16 07:13:05 -05:00
|
|
|
end
|
|
|
|
end
|
2000-10-02 03:48:42 -04:00
|
|
|
rescue Errno::ENOENT
|
1998-01-16 07:13:05 -05:00
|
|
|
end
|
2000-10-02 03:48:42 -04:00
|
|
|
end
|
1998-01-16 07:13:05 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def prune
|
|
|
|
throw :prune
|
|
|
|
end
|
|
|
|
module_function :find, :prune
|
|
|
|
end
|