Hi,
You reach this limit because you are stacking forever: your search
method has no argument, so no recursion occures. You have to pass the
path of the subdirectory to search into to the search method.
Another (better) way is to use the "find" standard library of Ruby.
require "find"
Find.find(".") do |f|
puts f
end
(I haven't tested this code but it should work).
It will do the work for you.
Regards,
Come
On 6 juil, 08:45, "Alexander Fleck" <F...@schleissheimer.de> wrote:
> hi,
> I want to walk through a directory recursively.
>
> I have the follwing code:
>
> '
> #!/usr/bin/env ruby
>
> def search
> Dir.foreach(".\\") { |x|
> if File.directory?(x)
> search
> else
> open(x) do |file|
> file.each { |l| puts l}
> end
> puts x
> end
> }
> end
>
> search
> '
>
> I get a 'stack level too deep'-error. What does that mean and how can I
> avoid it?
>
> thanks,
> Alex.