Zachary Holt
6/14/2007 9:58:00 PM
On Jun 14, 2007, at 1:47 PM, Jerry Blanco wrote:
> Hi,
Hi.
> def rename(headOfTree, what, withWhat)
> p = Pathname.new(headOfTree)
> p.find() do |file|
> path = file.to_s #just to make it prettier
> File.rename(path, path.gsub("#{what}", withWhat)) if path.include?
> (what)
> end
> end
> Is there a way to traverse a directory leaves-first? (bottom-to-top)
def rename( headOfTree, what, withWhat )
p = Pathname.new( headOfTree )
p.each_entry do |file|
path = file.to_s #just to make it prettier
next if path =~ /^\.\.?$/
rename( path, what, withWhat ) if path.directory?
File.rename( path, path.gsub( "#{what}", withWhat ) ) if
path.include?( what )
end
end
This code is untested, but if you recurse before you rename, you
should get what you want.