> Something like this should work:
>
> # Implement this properly
> def html_escape(s)
>   s
> end

Why are we escaping html? It's just a list of file names, after all.

>
> def recurse_dir(dirname)
>   Dir.entries(dirname).sort.each do |filename|
>     if FileTest.directory? filename
>       puts "<div class=\"folder\">"
>       puts "<div class=\"title\">#{html_escape(filename)}</div>"
>       recurse_dir(filename)
>       puts "</div>"
>     elsif FileTest.file? filename
>       puts "<span class=\"file\">#{html_escape(filename)}</span>"
>     end
>   end
> end
>
> recurse_dir("/wherever/you/start")
>
> Eivind.

Your code looks good, but it just loops...
* trimmed.. *
<div class='folder'>
<div class='title'>.</div>
<div class='folder'>
<div class='title'>.</div>
<div class='folder'>
<div class='title'>.</div>
file_map_2.rb:7:in `recurse_dir': stack level too deep
(SystemStackError)
	from file_map_2.rb:11:in `recurse_dir'
	from file_map_2.rb:7:in `each'
	from file_map_2.rb:7:in `recurse_dir'
	from file_map_2.rb:11:in `recurse_dir'
	from file_map_2.rb:7:in `each'
	from file_map_2.rb:7:in `recurse_dir'
	from file_map_2.rb:11:in `recurse_dir'
	from file_map_2.rb:7:in `each'
	 ... 2311 levels...
	from file_map_2.rb:11:in `recurse_dir'
	from file_map_2.rb:7:in `each'
	from file_map_2.rb:7:in `recurse_dir'
	from file_map_2.rb:19

Looks like it should work to me. I don't see how it can be infinite.