On Thu, Apr 24, 2008 at 11:05 PM, John <john.d.perkins / gmail.com> wrote:
> Hola,
>  My boss asked me to make a nice map of the directories on our web
>  server for an upcoming meeting. I'm aware of several ways to approach
>  this, like find and tree, etc, but I'm a Ruby addict, so that's what
>  I'm using. This gets good, don't bail yet!
>
>  What I want to see looks like this:
>  <div class='folder'>
>   <div class='title'> Foldername </div>
>   <span class='file'> file1</span><span class='file'> file2</span>
>     <div class='folder'>
>     <div class='title'> Nested Foldername </div>
>     <span class='file'> file3</span><span class='file'> file4</span>
>   </div>
>  </div>
>
>  Thus, my nested folders appear nested on the page.
>
>  I start by doing a "ls -R > filemap.txt" on the directory I'm
>  interested in, and then I can process the output file:

I think this is your core problem.  Don't do that.

Something like this should work:

# Implement this properly
def html_escape(s)
  s
end

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.