From: Eivind Eklund Date: 2008-04-25T18:10:01+09:00 Subject: Re: pretty folder tree script On Thu, Apr 24, 2008 at 11:05 PM, John 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: >
>
Foldername
> file1 file2 >
>
Nested Foldername
> file3 file4 >
>
> > 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 "
" puts "
#{html_escape(filename)}
" recurse_dir(filename) puts "
" elsif FileTest.file? filename puts "#{html_escape(filename)}" end end end recurse_dir("/wherever/you/start") Eivind.