diff options
Diffstat (limited to 'lib/find.rb')
-rw-r--r-- | lib/find.rb | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/find.rb b/lib/find.rb new file mode 100644 index 0000000000..340461c653 --- /dev/null +++ b/lib/find.rb @@ -0,0 +1,38 @@ +# Usage: +# require "find.rb" +# +# Find.find('/foo','/bar') {|f| ...} +# or +# include Find +# find('/foo','/bar') {|f| ...} +# + +module Find + extend Find + + def findpath(path, ary) + ary.push(path) + d = Dir.open(path) + for f in d + continue if f =~ /^\.\.?$/ + f = path + "/" + f + if File.directory? f + findpath(f, ary) + else + ary.push(f) + end + end + end + private :findpath + + def find(*path) + ary = [] + for p in path + findpath(p, ary) + for f in ary + yield f + end + end + end + module_function :find +end |