1998-01-16 15:13:05 +03:00
|
|
|
# Usage:
|
1999-01-20 07:59:39 +03:00
|
|
|
# require "find"
|
1998-01-16 15:13:05 +03:00
|
|
|
#
|
|
|
|
# Find.find('/foo','/bar') {|f| ...}
|
|
|
|
# or
|
|
|
|
# include Find
|
|
|
|
# find('/foo','/bar') {|f| ...}
|
|
|
|
#
|
|
|
|
|
|
|
|
module Find
|
|
|
|
def find(*path)
|
2000-12-05 12:36:54 +03:00
|
|
|
path.collect!{|d| d.dup}
|
1998-01-16 15:13:05 +03:00
|
|
|
while file = path.shift
|
2000-10-02 11:48:42 +04:00
|
|
|
catch(:prune) do
|
1998-01-16 15:13:05 +03:00
|
|
|
yield file
|
2000-10-02 11: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 15:13:05 +03:00
|
|
|
end
|
2000-10-02 11:48:42 +04:00
|
|
|
ensure
|
|
|
|
d.close
|
1998-01-16 15:13:05 +03:00
|
|
|
end
|
|
|
|
end
|
2001-03-21 06:41:45 +03:00
|
|
|
rescue Errno::ENOENT, Errno::EACCES
|
1998-01-16 15:13:05 +03:00
|
|
|
end
|
2000-10-02 11:48:42 +04:00
|
|
|
end
|
1998-01-16 15:13:05 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def prune
|
|
|
|
throw :prune
|
|
|
|
end
|
|
|
|
module_function :find, :prune
|
|
|
|
end
|