From: Ezra Zygmuntowicz Date: 2005-07-08T06:21:26+09:00 Subject: Re: recursively descend and rename files. Thanks for everyones Ideas on this one. It works perfectly. If anyone has the need to do something similar heres the code: ---start-------- #!/usr/local/bin/ruby # recursively descend through directories and change filenames to be webserver compliant based on a regex. require 'find' require 'ftools' def rename(filename) new_name = File.join(File.dirname(filename), fix_name(File.basename (filename))) File.move(filename, new_name) end def fix_name(name) name.gsub!(/[\s_]/, "-") name.downcase! name.gsub!(/[^a-z0-9.-]*/, '') name.gsub!(/^-/,'') end path = "/Volumes/Users/ez/LOGOS" # change me to the path of the root folder you want to start from. Find.find(path) do |file| rename(file) end ----end--------- On Jul 7, 2005, at 12:54 PM, Ryan Leavengood wrote: > Ezra Zygmuntowicz said: > >> >> Can some one please point me in the right direction? >> > > require 'ftools' > > def rename(filename) > new_name = File.join(File.dirname(filename), > fix_name(File.basename(filename))) > File.move(filename, new_name) > end > > def fix_name(basename) > # whatever fixes the name > basename.gsub(/s/,'xxx') > end > __END__ > > Ryan > -Ezra Zygmuntowicz Yakima Herald-Republic WebMaster 509-577-7732 ezra@yakima-herald.com