Ransom Tullis:
> so I want:
> 
> \Test Dir1
> \TestDir2\TestDir 1
> 
> to change to
> 
> \test-dir1
> \testdir2\testdir-1
> 
> Which works fine on the top level, but is not recursing down to the
> next level. Filenames should be ignored.

Dir.entries is not recursive; you want 'find'.  But it has to be a
depth-first 'find': you can gradually replace the pillars of a
building if you start from the top, but not from the bottom.  (Mixing
metaphors on which direction is 'depth'.)

  require 'pathname'

  def find_depth_first(pathname)
    acc = []
    pathname.find { |file| acc << file }
    acc.reverse!
    acc.each { |path| yield path }
  end

  find_depth_first(Pathname(".")) { |path|
    if path.directory?
      new_path = path.dirname +
        Pathname(path.basename.to_s.downcase.gsub(/\s/, "-"))
      if new_path != path
        path.rename(new_path)
      end
    end
  }


-- 
Posted via http://www.ruby-forum.com/.